當前位置: 首頁>>代碼示例>>PHP>>正文


PHP AbstractCollection::getAllIds方法代碼示例

本文整理匯總了PHP中Magento\Framework\Model\Resource\Db\Collection\AbstractCollection::getAllIds方法的典型用法代碼示例。如果您正苦於以下問題:PHP AbstractCollection::getAllIds方法的具體用法?PHP AbstractCollection::getAllIds怎麽用?PHP AbstractCollection::getAllIds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Framework\Model\Resource\Db\Collection\AbstractCollection的用法示例。


在下文中一共展示了AbstractCollection::getAllIds方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: massAction

 /**
  * Batch print shipping labels for whole shipments.
  * Push pdf document with shipping labels to user browser
  *
  * @param AbstractCollection $collection
  * @return ResponseInterface|void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function massAction(AbstractCollection $collection)
 {
     $request = $this->getRequest();
     $ids = $collection->getAllIds();
     $createdFromOrders = !empty($ids);
     $shipments = null;
     $labelsContent = [];
     switch ($request->getParam('massaction_prepare_key')) {
         case 'shipment_ids':
             $ids = $request->getParam('shipment_ids');
             array_filter($ids, 'intval');
             if (!empty($ids)) {
                 $shipments = $this->_objectManager->create('Magento\\Sales\\Model\\Resource\\Order\\Shipment\\Collection')->addFieldToFilter('entity_id', ['in' => $ids]);
             }
             break;
         case 'order_ids':
             $ids = $request->getParam('order_ids');
             array_filter($ids, 'intval');
             if (!empty($ids)) {
                 $shipments = $this->_objectManager->create('Magento\\Sales\\Model\\Resource\\Order\\Shipment\\Collection')->setOrderFilter(['in' => $ids]);
             }
             break;
     }
     if ($shipments && $shipments->getSize()) {
         foreach ($shipments as $shipment) {
             $labelContent = $shipment->getShippingLabel();
             if ($labelContent) {
                 $labelsContent[] = $labelContent;
             }
         }
     }
     if (!empty($labelsContent)) {
         $outputPdf = $this->labelGenerator->combineLabelsPdf($labelsContent);
         return $this->_fileFactory->create('ShippingLabels.pdf', $outputPdf->render(), DirectoryList::VAR_DIR, 'application/pdf');
     }
     if ($createdFromOrders) {
         $this->messageManager->addError(__('There are no shipping labels related to selected orders.'));
         $this->_redirect('sales/order/index');
     } else {
         $this->messageManager->addError(__('There are no shipping labels related to selected shipments.'));
         $this->_redirect('sales/shipment/index');
     }
 }
開發者ID:nja78,項目名稱:magento2,代碼行數:51,代碼來源:MassPrintShippingLabel.php

示例2: delete

 /**
  * Delete collection items
  *
  * @param AbstractCollection $collection
  * @return int
  */
 protected function delete(AbstractCollection $collection)
 {
     $count = 0;
     foreach ($collection->getAllIds() as $id) {
         /** @var \Magento\Framework\Model\AbstractModel $model */
         $model = $this->_objectManager->get($this->model);
         $model->load($id);
         $model->delete();
         ++$count;
     }
     return $count;
 }
開發者ID:refaelgold,項目名稱:magento2_blog,代碼行數:18,代碼來源:AbstractMassDelete.php

示例3: testGetAllIdsWithBind

 public function testGetAllIdsWithBind()
 {
     $this->_model->getSelect()->where('code = :code');
     $this->_model->addBindParam('code', 'admin');
     $this->assertEquals(['0'], $this->_model->getAllIds());
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:6,代碼來源:AbstractTest.php

示例4: setStatus

 /**
  * Set status to collection items
  *
  * @param AbstractCollection $collection
  * @return void
  */
 protected function setStatus(AbstractCollection $collection)
 {
     foreach ($collection->getAllIds() as $id) {
         /** @var \Magento\Framework\Model\AbstractModel $model */
         $model = $this->_objectManager->get($this->model);
         $model->load($id);
         $model->setIsActive($this->status);
         $model->save();
     }
 }
開發者ID:refaelgold,項目名稱:magento2_blog,代碼行數:16,代碼來源:AbstractMassStatus.php

示例5: getAllIds

 /**
  * Retrieve all ids for collection
  *
  * @return array
  */
 public function getAllIds()
 {
     if ($this->_itemIds === null) {
         $this->_itemIds = parent::getAllIds();
     }
     return $this->_itemIds;
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:12,代碼來源:Collection.php

示例6: getAllIds

 /**
  * Retrieve all ids for collection
  *
  * @return array
  */
 public function getAllIds()
 {
     if (is_null($this->_itemIds)) {
         $this->_itemIds = parent::getAllIds();
     }
     return $this->_itemIds;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:12,代碼來源:Collection.php


注:本文中的Magento\Framework\Model\Resource\Db\Collection\AbstractCollection::getAllIds方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。