/** * Exports visible products from the current store. * Result can be limited by the `limit` and `offset` GET parameters. */ public function productAction() { if (Mage::helper('nosto_tagging')->isModuleEnabled()) { $pageSize = (int) $this->getRequest()->getParam('limit', 100); $currentOffset = (int) $this->getRequest()->getParam('offset', 0); $currentPage = $currentOffset / $pageSize + 1; $products = Mage::getModel('catalog/product')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId())->addAttributeToSelect('*')->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED))->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setPageSize($pageSize)->setCurPage($currentPage); if ($currentPage > $products->getLastPageNumber()) { $products = array(); } $collection = new NostoExportProductCollection(); foreach ($products as $product) { if ($product->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && (int) $product->getPriceType() === Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) { continue; } $meta = new Nosto_Tagging_Model_Meta_Product(); $meta->loadData($product); $validator = new NostoValidator($meta); if ($validator->validate()) { $collection[] = $meta; } } $this->export($collection); } }
/** * Event handler for the "catalog_product_save_after" event. * Sends a product update API call to Nosto. * * @param Varien_Event_Observer $observer the event observer. * * @return Nosto_Tagging_Model_Observer */ public function sendProductUpdate(Varien_Event_Observer $observer) { if (Mage::helper('nosto_tagging')->isModuleEnabled()) { /** @var Mage_Catalog_Model_Product $product */ $product = $observer->getEvent()->getProduct(); // Always "upsert" 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. foreach ($product->getStoreIds() as $storeId) { $store = Mage::app()->getStore($storeId); /** @var NostoAccount $account */ $account = Mage::helper('nosto_tagging/account')->find($store); if ($account === null || !$account->isConnectedToNosto()) { continue; } // Load the product model for this particular store view. $product = Mage::getModel('catalog/product')->setStoreId($store->getId())->load($product->getId()); if (is_null($product)) { continue; } if (!$product->isVisibleInSiteVisibility()) { continue; } $model = new Nosto_Tagging_Model_Meta_Product(); $model->loadData($product, $store); // Only send product update if we have all required // data for the product model. $validator = new NostoValidator($model); if ($validator->validate()) { try { $op = new NostoOperationProduct($account); $op->addProduct($model); $op->upsert(); } catch (NostoException $e) { Mage::log("\n" . $e, Zend_Log::ERR, 'nostotagging.log'); } } } } return $this; }