Пример #1
0
 /**
  * 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');
     }
 }
 /**
  * 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;
 }
Пример #3
0
 public function testGetAllIdsWithBind()
 {
     $this->_model->getSelect()->where('code = :code');
     $this->_model->addBindParam('code', 'admin');
     $this->assertEquals(['0'], $this->_model->getAllIds());
 }
 /**
  * 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();
     }
 }
Пример #5
0
 /**
  * Retrieve all ids for collection
  *
  * @return array
  */
 public function getAllIds()
 {
     if ($this->_itemIds === null) {
         $this->_itemIds = parent::getAllIds();
     }
     return $this->_itemIds;
 }
Пример #6
0
 /**
  * Retrieve all ids for collection
  *
  * @return array
  */
 public function getAllIds()
 {
     if (is_null($this->_itemIds)) {
         $this->_itemIds = parent::getAllIds();
     }
     return $this->_itemIds;
 }