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


PHP AbstractCollection::getItems方法代码示例

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


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

示例1: massAction

 /**
  * Print credit memos for selected orders
  *
  * @param AbstractCollection $collection
  * @return ResponseInterface|\Magento\Backend\Model\View\Result\Redirect
  */
 protected function massAction(AbstractCollection $collection)
 {
     $resultRedirect = $this->resultRedirectFactory->create();
     $flag = false;
     /** @var \Magento\Sales\Model\Order $order */
     foreach ($collection->getItems() as $order) {
         $creditmemos = $order->getCreditmemosCollection();
         if ($creditmemos->getSize()) {
             $flag = true;
             if (!isset($pdf)) {
                 $pdf = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Creditmemo')->getPdf($creditmemos);
             } else {
                 $pages = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Creditmemo')->getPdf($creditmemos);
                 $pdf->pages = array_merge($pdf->pages, $pages->pages);
             }
         }
     }
     if ($flag) {
         $date = $this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\DateTime')->date('Y-m-d_H-i-s');
         return $this->_fileFactory->create('creditmemo' . $date . '.pdf', $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf');
     } else {
         $this->messageManager->addError(__('There are no printable documents related to selected orders.'));
         $resultRedirect->setPath('sales/*/');
         return $resultRedirect;
     }
 }
开发者ID:nja78,项目名称:magento2,代码行数:32,代码来源:Pdfcreditmemos.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;
         }
         $order->hold();
         $order->save();
         $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('sales/*/');
     return $resultRedirect;
 }
开发者ID:nja78,项目名称:magento2,代码行数:30,代码来源: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('sales/*/');
     return $resultRedirect;
 }
开发者ID:nja78,项目名称:magento2,代码行数:30,代码来源:MassCancel.php

示例4: applySalableProductTypesFilter

 /**
  * Filter collection by removing not available product types
  *
  * @param \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection $collection
  * @return \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection
  */
 public function applySalableProductTypesFilter($collection)
 {
     $productTypes = $this->_salesConfig->getAvailableProductTypes();
     foreach ($collection->getItems() as $key => $item) {
         if ($item instanceof \Magento\Catalog\Model\Product) {
             $type = $item->getTypeId();
         } elseif ($item instanceof \Magento\Sales\Model\Order\Item) {
             $type = $item->getProductType();
         } elseif ($item instanceof \Magento\Quote\Model\Quote\Item) {
             $type = $item->getProductType();
         } else {
             $type = '';
         }
         if (!in_array($type, $productTypes)) {
             $collection->removeItemByKey($key);
         }
     }
     return $collection;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:25,代码来源:Admin.php


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