Пример #1
0
 /**
  * @inheritdoc
  */
 protected function doRequest(\NostoServiceProduct $operation)
 {
     $operation->upsert();
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 protected function doRequest(\NostoServiceProduct $operation)
 {
     $operation->delete();
 }
Пример #3
0
 /**
  * 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]);
             }
         }
     }
 }