コード例 #1
0
ファイル: Save.php プロジェクト: Nosto/nosto-magento2
 /**
  * Event handler for the "catalog_product_save_after" and  event.
  * Sends a product update API call to Nosto.
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->_moduleManager->isEnabled('Nosto_Tagging')) {
         /* @var Order $order */
         $order = $observer->getOrder();
         $nostoOrder = $this->_orderBuilder->build($order);
         $nostoAccount = $this->_accountHelper->findAccount($this->_storeManager->getStore());
         if ($nostoAccount !== null) {
             $quoteId = $order->getQuoteId();
             $nostoCustomer = $this->_customerFactory->create()->load($quoteId, NostoCustomer::QUOTE_ID);
             $orderService = new \NostoServiceOrder($nostoAccount);
             try {
                 $orderService->confirm($nostoOrder, $nostoCustomer->getNostoId());
             } catch (\Exception $e) {
                 $this->_logger->error(sprintf("Failed to save order with qoute #%s for customer #%s.\n                        Message was: %s", $quoteId, $nostoCustomer->getNostoId(), $e->getMessage()));
             }
         }
     }
 }
コード例 #2
0
ファイル: Base.php プロジェクト: Nosto/nosto-magento2
 /**
  * Event handler for the "catalog_product_save_after" and  event.
  * Sends a product update API call to Nosto.
  *
  * @param Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     if ($this->_moduleManager->isEnabled('Nosto_Tagging')) {
         // Always "delete" the product for all stores it is available in.
         // This is done to avoid data inconsistencies as even if a product
         // is edited for only one store, the updated data can reflect in
         // other stores as well.
         /* @var \Magento\Catalog\Model\Product $product */
         /** @noinspection PhpUndefinedMethodInspection */
         $product = $observer->getProduct();
         foreach ($product->getStoreIds() as $storeId) {
             /** @var Store $store */
             $store = $this->_storeManager->getStore($storeId);
             /** @var \NostoAccount $account */
             $account = $this->_accountHelper->findAccount($store);
             if ($account === null) {
                 continue;
             }
             if (!$this->validateProduct($product)) {
                 continue;
             }
             // Load the product model for this particular store view.
             /** @var \NostoProduct $model */
             $metaProduct = $this->_productBuilder->build($product, $store);
             if (is_null($metaProduct)) {
                 continue;
             }
             try {
                 $op = new \NostoServiceProduct($account);
                 $op->addProduct($metaProduct);
                 $this->doRequest($op);
             } catch (\NostoException $e) {
                 $this->_logger->error($e, ['exception' => $e]);
             }
         }
     }
 }