Exemplo n.º 1
0
 /**
  * Notify collection items
  *
  * @param AbstractCollection $collection
  * @return int
  */
 protected function notify($collection)
 {
     $count = 0;
     $this->_mailer = $this->_objectManager->get('Alin\\Cadou\\Model\\Mailer');
     foreach ($collection->getAllIds() as $id) {
         /** @var \Magento\Framework\Model\AbstractModel $model */
         $model = $this->_objectManager->get($this->model);
         $model->load($id);
         $data = $model->getOrigData();
         $data['name'] = $data['fullname'];
         $mediaUrl = $this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore($data['store_id'])->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . 'catalog/product';
         $productSelect = $this->_objectManager->create('Alin\\Cadou\\Model\\Cadou\\Source\\ProductSelect');
         $product_names = $productSelect->toOptionHash();
         $data['productname'] = $product_names[$data['product_id']];
         $product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product');
         $product = $product->setStoreId($data['store_id'])->load($data['product_id']);
         $data['producturl'] = $product->getUrlInStore();
         $data['productimage'] = $product->getImage();
         $customerData = $this->_objectManager->create('Magento\\Quote\\Model\\Quote');
         $customerData->loadByIdWithoutStore($data['quote_id']);
         if (!empty($data['child_cart_item_id'])) {
             $cart_item = $customerData->getItemById($data['cart_item_id'])->toArray();
             $product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product');
             //recreate product object
             $product = $product->setStoreId($data['store_id'])->load($cart_item['product_id']);
             $data['producturl'] = $product->getUrlInStore();
         }
         if (!empty($data['productimage'])) {
             $data['productimage'] = $mediaUrl . $data['productimage'];
         }
         if ($customerData->getCustomerIsGuest()) {
             $data['customer_name'] = 'Guest';
             $data['customer_email'] = $customerData->getCustomerEmail();
         } else {
             $data['customer_name'] = $customerData->getCustomerFirstname() . ' ' . $customerData->getCustomerLastname();
             $data['customer_email'] = $customerData->getCustomerEmail();
         }
         $resp = $this->_mailer->sendNotification($data);
         if ($resp == true) {
             $model->setNotified(true);
             $model->save();
             ++$count;
         }
     }
     return $count;
 }
Exemplo n.º 2
0
 /**
  * Delete collection items
  *
  * @param AbstractCollection $collection
  * @return int
  */
 protected function delete($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;
 }