Esempio n. 1
0
 /**
  * Set created_at parameter
  *
  * @return \Magento\Framework\Model\AbstractModel
  */
 public function beforeSave()
 {
     $date = $this->_dateFactory->create()->gmtDate();
     if ($this->isObjectNew() && !$this->getCreatedAt()) {
         $this->setCreatedAt($date);
     } else {
         $this->setUpdatedAt($date);
     }
     return parent::beforeSave();
 }
Esempio n. 2
0
 /**
  * Before save action
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if (is_null($object->getId()) && $object->getCustomerId() && $object->getProductId() && $object->getWebsiteId()) {
         if ($row = $this->_getAlertRow($object)) {
             $object->addData($row);
             $object->setStatus(0);
         }
     }
     if (is_null($object->getAddDate())) {
         $object->setAddDate($this->_dateFactory->create()->gmtDate());
         $object->setStatus(0);
     }
     return parent::_beforeSave($object);
 }
Esempio n. 3
0
 /**
  * Verify data required for saving
  *
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 protected function _beforeSave()
 {
     if (!$this->getId()) {
         $this->setCreatedAt($this->_dateFactory->create()->gmtDate());
     }
     return parent::_beforeSave();
 }
Esempio n. 4
0
 /**
  * Process stock emails
  *
  * @param \Magento\ProductAlert\Model\Email $email
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function _processStock(\Magento\ProductAlert\Model\Email $email)
 {
     $email->setType('stock');
     foreach ($this->_getWebsites() as $website) {
         /* @var $website \Magento\Store\Model\Website */
         if (!$website->getDefaultGroup() || !$website->getDefaultGroup()->getDefaultStore()) {
             continue;
         }
         if (!$this->_scopeConfig->getValue(self::XML_PATH_STOCK_ALLOW, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $website->getDefaultGroup()->getDefaultStore()->getId())) {
             continue;
         }
         try {
             $collection = $this->_stockColFactory->create()->addWebsiteFilter($website->getId())->addStatusFilter(0)->setCustomerOrder();
         } catch (\Exception $e) {
             $this->_errors[] = $e->getMessage();
             return $this;
         }
         $previousCustomer = null;
         $email->setWebsite($website);
         foreach ($collection as $alert) {
             try {
                 if (!$previousCustomer || $previousCustomer->getId() != $alert->getCustomerId()) {
                     $customer = $this->customerRepository->getById($alert->getCustomerId());
                     if ($previousCustomer) {
                         $email->send();
                     }
                     if (!$customer) {
                         continue;
                     }
                     $previousCustomer = $customer;
                     $email->clean();
                     $email->setCustomerData($customer);
                 } else {
                     $customer = $previousCustomer;
                 }
                 $product = $this->productRepository->getById($alert->getProductId(), false, $website->getDefaultStore()->getId());
                 $product->setCustomerGroupId($customer->getGroupId());
                 if ($product->isSalable()) {
                     $email->addStockProduct($product);
                     $alert->setSendDate($this->_dateFactory->create()->gmtDate());
                     $alert->setSendCount($alert->getSendCount() + 1);
                     $alert->setStatus(1);
                     $alert->save();
                 }
             } catch (\Exception $e) {
                 $this->_errors[] = $e->getMessage();
             }
         }
         if ($previousCustomer) {
             try {
                 $email->send();
             } catch (\Exception $e) {
                 $this->_errors[] = $e->getMessage();
             }
         }
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing Gift Registry:');
     $fixtureFile = 'GiftRegistry/gift_registry.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $giftRegistryData) {
         /** @var \Magento\GiftRegistry\Model\Resource\Entity\Collection $collection */
         $collection = $this->collectionFactory->create();
         $collection->addFilter('title', $giftRegistryData['title']);
         if ($collection->count() > 0) {
             continue;
         }
         $data = $this->generateData($giftRegistryData);
         /** @var \Magento\GiftRegistry\Model\Entity $giftRegistry */
         $giftRegistry = $this->giftRegistryFactory->create();
         $address = $this->addressFactory->create();
         $address->setData($data['address']);
         $giftRegistry->setTypeById($data['type_id']);
         $giftRegistry->importData($data);
         $giftRegistry->addData(['customer_id' => $data['customer_id'], 'website_id' => $this->storeManager->getWebsiteId(), 'url_key' => $giftRegistry->getGenerateKeyId(), 'created_at' => $this->dateFactory->create()->date(), 'is_add_action' => true]);
         $giftRegistry->importAddress($address);
         $validationPassed = $giftRegistry->validate();
         if ($validationPassed) {
             $giftRegistry->save();
             foreach ($data['items'] as $productId) {
                 $parentId = $this->productIndexer->getRelationsByChild($productId);
                 $itemProduct = $parentId ? $parentId[0] : $productId;
                 $itemOptions = $this->formItemOptions($productId);
                 $item = $this->itemFactory->create();
                 $item->setEntityId($giftRegistry->getId())->setProductId($itemProduct)->setQty(1)->setOptions($itemOptions)->save();
             }
         }
         $this->logger->logInline('.');
     }
 }
Esempio n. 6
0
 /**
  * Verify data required for saving
  *
  * @return $this
  */
 public function beforeSave()
 {
     // set parent id
     $this->_verifyPaymentObject();
     if (!$this->getId()) {
         // We need to set order and payment ids only for new transactions
         if (null !== $this->_paymentObject) {
             $this->setPaymentId($this->_paymentObject->getId());
         }
         if (null !== $this->_order) {
             $this->setOrderId($this->_order->getId());
         }
         $this->setCreatedAt($this->_dateFactory->create()->gmtDate());
     }
     return parent::beforeSave();
 }
Esempio n. 7
0
 /**
  * Before Event save process
  *
  * @return $this
  */
 public function beforeSave()
 {
     $date = $this->_dateFactory->create();
     $this->setLoggedAt($date->gmtDate());
     return parent::beforeSave();
 }
Esempio n. 8
0
 /**
  * Verify data required for saving
  *
  * @return $this
  */
 public function beforeSave()
 {
     if (!$this->getOrderId() && $this->getOrder()) {
         $this->setOrderId($this->getOrder()->getId());
     }
     if (!$this->getPaymentId() && $this->getOrder() && $this->getOrder()->getPayment()) {
         $this->setPaymentId($this->getOrder()->getPayment()->getId());
     }
     // set parent id
     $this->_verifyPaymentObject();
     if (!$this->getId()) {
         $this->setCreatedAt($this->_dateFactory->create()->gmtDate());
     }
     return parent::beforeSave();
 }
Esempio n. 9
0
 /**
  * Before Event save process
  *
  * @return $this
  */
 protected function _beforeSave()
 {
     $date = $this->_dateFactory->create();
     $this->setLoggedAt($date->gmtDate());
     return parent::_beforeSave();
 }