public function execute(\Magento\Framework\Event\Observer $observer)
 {
     // get the product object
     $_product = $observer->getProduct();
     // pass the SKU to Processwire
     $this->updateWireProduct($_product, 'On Save');
 }
Example #2
0
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $data = $this->_request->getParams();
     $product = $observer->getProduct();
     $billing = $data['product']['billing_options_table'];
     $model = $this->_attributeFactory->create();
     $attributeId = $product->getResource()->getAttribute('billing_options')->getAttributeId();
     $productId = $product->getId();
     /** @var \Magenest\Subscription\Model\Attribute $model */
     $modelCollection = $model->getCollection();
     $modelCollection->addFieldToFilter('attribute_id', $attributeId);
     $modelCollection->addFieldToFilter('entity_id', $productId);
     $object = $modelCollection->getFirstItem();
     if ($object->getId()) {
         $object->setValue($billing)->save();
     } else {
         $data = ['attribute_id' => $attributeId, 'entity_id' => $productId, 'value' => $billing];
         $model->setData($data)->save();
     }
 }
Example #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]);
             }
         }
     }
 }