当前位置: 首页>>代码示例>>PHP>>正文


PHP AbstractCollection::count方法代码示例

本文整理汇总了PHP中Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection::count方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractCollection::count方法的具体用法?PHP AbstractCollection::count怎么用?PHP AbstractCollection::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection的用法示例。


在下文中一共展示了AbstractCollection::count方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: massAction

 /**
  * Unhold selected orders
  *
  * @param AbstractCollection $collection
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 protected function massAction(AbstractCollection $collection)
 {
     $countUnHoldOrder = 0;
     /** @var \Magento\Sales\Model\Order $order */
     foreach ($collection->getItems() as $order) {
         $order->load($order->getId());
         if (!$order->canUnhold()) {
             continue;
         }
         $order->unhold();
         $order->save();
         $countUnHoldOrder++;
     }
     $countNonUnHoldOrder = $collection->count() - $countUnHoldOrder;
     if ($countNonUnHoldOrder && $countUnHoldOrder) {
         $this->messageManager->addError(__('%1 order(s) were not released from on hold status.', $countNonUnHoldOrder));
     } elseif ($countNonUnHoldOrder) {
         $this->messageManager->addError(__('No order(s) were released from on hold status.'));
     }
     if ($countUnHoldOrder) {
         $this->messageManager->addSuccess(__('%1 order(s) have been released from on hold status.', $countUnHoldOrder));
     }
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setPath($this->getComponentRefererUrl());
     return $resultRedirect;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:32,代码来源:MassUnhold.php

示例2: massAction

 /**
  * Hold selected orders
  *
  * @param AbstractCollection $collection
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 protected function massAction(AbstractCollection $collection)
 {
     $countHoldOrder = 0;
     foreach ($collection->getItems() as $order) {
         if (!$order->canHold()) {
             continue;
         }
         $this->orderManagement->hold($order->getEntityId());
         $countHoldOrder++;
     }
     $countNonHoldOrder = $collection->count() - $countHoldOrder;
     if ($countNonHoldOrder && $countHoldOrder) {
         $this->messageManager->addError(__('%1 order(s) were not put on hold.', $countNonHoldOrder));
     } elseif ($countNonHoldOrder) {
         $this->messageManager->addError(__('No order(s) were put on hold.'));
     }
     if ($countHoldOrder) {
         $this->messageManager->addSuccess(__('You have put %1 order(s) on hold.', $countHoldOrder));
     }
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setPath($this->getComponentRefererUrl());
     return $resultRedirect;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:29,代码来源:MassHold.php

示例3: massAction

 /**
  * Cancel selected orders
  *
  * @param AbstractCollection $collection
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 protected function massAction(AbstractCollection $collection)
 {
     $countCancelOrder = 0;
     foreach ($collection->getItems() as $order) {
         if (!$order->canCancel()) {
             continue;
         }
         $order->cancel();
         $order->save();
         $countCancelOrder++;
     }
     $countNonCancelOrder = $collection->count() - $countCancelOrder;
     if ($countNonCancelOrder && $countCancelOrder) {
         $this->messageManager->addError(__('%1 order(s) cannot be canceled.', $countNonCancelOrder));
     } elseif ($countNonCancelOrder) {
         $this->messageManager->addError(__('You cannot cancel the order(s).'));
     }
     if ($countCancelOrder) {
         $this->messageManager->addSuccess(__('We canceled %1 order(s).', $countCancelOrder));
     }
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setPath($this->getComponentRefererUrl());
     return $resultRedirect;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:30,代码来源:MassCancel.php

示例4: massAction

 /**
  * Cancel selected orders
  *
  * @param AbstractCollection $collection
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 protected function massAction(AbstractCollection $collection)
 {
     $countCancelOrder = 0;
     $connection = $this->_resource->getConnection(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION);
     $showTables = $connection->fetchCol('show tables');
     //start get table name
     $tblSalesOrder = $connection->getTableName('sales_order');
     $tblSalesCreditmemoComment = $connection->getTableName('sales_creditmemo_comment');
     $tblSalesCreditmemoItem = $connection->getTableName('sales_creditmemo_item');
     $tblSalesCreditmemo = $connection->getTableName('sales_creditmemo');
     $tblSalesCreditmemoGrid = $connection->getTableName('sales_creditmemo_grid');
     $tblSalesInvoiceComment = $connection->getTableName('sales_invoice_comment');
     $tblSalesInvoiceItem = $connection->getTableName('sales_invoice_item');
     $tblSalesInvoice = $connection->getTableName('sales_invoice');
     $tblSalesInvoiceGrid = $connection->getTableName('sales_invoice_grid');
     $tblQuoteAddressItem = $connection->getTableName('quote_address_item');
     $tblQuoteItemOption = $connection->getTableName('quote_item_option');
     $tblQuote = $connection->getTableName('quote');
     $tblQuoteAddress = $connection->getTableName('quote_address');
     $tblQuoteItem = $connection->getTableName('quote_item');
     $tblQuotePayment = $connection->getTableName('quote_payment');
     $tblQuoteShippingRate = $connection->getTableName('quote_shipping_rate');
     $tblQuoteIDMask = $connection->getTableName('quote_id_mask');
     $tblSalesShipmentComment = $connection->getTableName('sales_shipment_comment');
     $tblSalesShipmentItem = $connection->getTableName('sales_shipment_item');
     $tblSalesShipmentTrack = $connection->getTableName('sales_shipment_track');
     $tblSalesShipment = $connection->getTableName('sales_shipment');
     $tblSalesShipmentGrid = $connection->getTableName('sales_shipment_grid');
     $tblSalesOrderAddress = $connection->getTableName('sales_order_address');
     $tblSalesOrderItem = $connection->getTableName('sales_order_item');
     $tblSalesOrderPayment = $connection->getTableName('sales_order_payment');
     $tblSalesOrderStatusHistory = $connection->getTableName('sales_order_status_history');
     $tblSalesOrderGrid = $connection->getTableName('sales_order_grid');
     $tblLogQuote = $connection->getTableName('log_quote');
     $showTablesLog = $connection->fetchCol('SHOW TABLES LIKE ?', '%' . $tblLogQuote);
     $tblSalesOrderTax = $connection->getTableName('sales_order_tax');
     foreach ($collection->getItems() as $order) {
         $orderId = $order->getId();
         if ($order->getIncrementId()) {
             $incId = $order->getIncrementId();
             if (in_array($tblSalesOrder, $showTables)) {
                 $result1 = $connection->fetchAll('SELECT quote_id FROM `' . $tblSalesOrder . '` WHERE entity_id=' . $orderId);
                 $quoteId = (int) $result1[0]['quote_id'];
             }
             $connection->rawQuery('SET FOREIGN_KEY_CHECKS=1');
             if (in_array($tblSalesCreditmemoComment, $showTables)) {
                 $connection->rawQuery('DELETE FROM `' . $tblSalesCreditmemoComment . '` WHERE parent_id IN (SELECT entity_id FROM `' . $tblSalesCreditmemo . '` WHERE order_id=' . $orderId . ')');
             }
             if (in_array('sales__creditmemo_item', $showTables)) {
                 $connection->rawQuery('DELETE FROM `' . $tblSalesCreditmemoItem . '` WHERE parent_id IN (SELECT entity_id FROM `' . $tblSalesCreditmemo . '` WHERE order_id=' . $orderId . ')');
             }
             if (in_array($tblSalesCreditmemo, $showTables)) {
                 $connection->rawQuery('DELETE FROM `' . $tblSalesCreditmemo . '` WHERE order_id=' . $orderId);
             }
             if (in_array($tblSalesCreditmemoGrid, $showTables)) {
                 $connection->rawQuery('DELETE FROM `' . $tblSalesCreditmemoGrid . '` WHERE order_id=' . $orderId);
             }
             if (in_array($tblSalesInvoiceComment, $showTables)) {
                 $connection->rawQuery('DELETE FROM `' . $tblSalesInvoiceComment . '` WHERE parent_id IN (SELECT entity_id FROM `' . $tblSalesInvoice . '` WHERE order_id=' . $orderId . ')');
             }
             if (in_array($tblSalesInvoiceItem, $showTables)) {
                 $connection->rawQuery('DELETE FROM `' . $tblSalesInvoiceItem . '` WHERE parent_id IN (SELECT entity_id FROM `' . $tblSalesInvoice . '` WHERE order_id=' . $orderId . ')');
             }
             if (in_array($tblSalesInvoice, $showTables)) {
                 $connection->rawQuery('DELETE FROM `' . $tblSalesInvoice . '` WHERE order_id=' . $orderId);
             }
             if (in_array($tblSalesInvoiceGrid, $showTables)) {
                 $connection->rawQuery('DELETE FROM `' . $tblSalesInvoiceGrid . '` WHERE order_id=' . $orderId);
             }
             if ($quoteId) {
                 if (in_array($tblQuoteAddressItem, $showTables)) {
                     $connection->rawQuery('DELETE FROM `' . $tblQuoteAddressItem . '` WHERE parent_item_id IN (SELECT address_id FROM `' . $tblQuoteAddress . '` WHERE quote_id=' . $quoteId . ')');
                 }
                 if (in_array($tblQuoteShippingRate, $showTables)) {
                     $connection->rawQuery('DELETE FROM `' . $tblQuoteShippingRate . '` WHERE address_id IN (SELECT address_id FROM `' . $tblQuoteAddress . '` WHERE quote_id=' . $quoteId . ')');
                 }
                 if (in_array($tblQuoteIDMask, $showTables)) {
                     $connection->rawQuery('DELETE FROM `' . $tblQuoteIDMask . '` where quote_id=' . $quoteId);
                 }
                 if (in_array($tblQuoteItemOption, $showTables)) {
                     $connection->rawQuery('DELETE FROM `' . $tblQuoteItemOption . '` WHERE item_id IN (SELECT item_id FROM `' . $tblQuoteItem . '` WHERE quote_id=' . $quoteId . ')');
                 }
                 if (in_array($tblQuote, $showTables)) {
                     $connection->rawQuery('DELETE FROM `' . $tblQuote . '` WHERE entity_id=' . $quoteId);
                 }
                 if (in_array($tblQuoteAddress, $showTables)) {
                     $connection->rawQuery('DELETE FROM `' . $tblQuoteAddress . '` WHERE quote_id=' . $quoteId);
                 }
                 if (in_array($tblQuoteItem, $showTables)) {
                     $connection->rawQuery('DELETE FROM `' . $tblQuoteItem . '` WHERE quote_id=' . $quoteId);
                 }
                 if (in_array('sales__quotePayment', $showTables)) {
                     $connection->rawQuery('DELETE FROM `' . $tblQuotePayment . '` WHERE quote_id=' . $quoteId);
                 }
//.........这里部分代码省略.........
开发者ID:Rukhsar,项目名称:magento2-DeleteOrder-extension,代码行数:101,代码来源:MassDelete.php


注:本文中的Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection::count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。