/** * Tests that product delete API requests can be made. */ public function testSendingProductDelete() { $account = new NostoAccount('platform-00000000'); $product = new NostoProduct(); $token = new NostoApiToken('products', '01098d0fc84ded7c4226820d5d1207c69243cbb3637dc4bc2a216dafcf09d783'); $account->addApiToken($token); $op = new NostoOperationProduct($account); $op->addProduct($product); $result = $op->delete(); $this->specify('successful product delete', function () use($result) { $this->assertTrue($result); }); }
/** * Event handler for the "catalog_product_delete_after" event. * Sends a product delete API call to Nosto. * * @param Varien_Event_Observer $observer the event observer. * * @return Nosto_Tagging_Model_Observer */ public function sendProductDelete(Varien_Event_Observer $observer) { if (Mage::helper('nosto_tagging')->isModuleEnabled()) { /** @var Mage_Catalog_Model_Product $product */ $product = $observer->getEvent()->getProduct(); // Products are always deleted from all store views, regardless of // the store view scope switcher on the product edit page. /** @var Mage_Core_Model_Store $store */ foreach (Mage::app()->getStores() as $store) { /** @var NostoAccount $account */ $account = Mage::helper('nosto_tagging/account')->find($store); if ($account === null || !$account->isConnectedToNosto()) { continue; } /** @var Nosto_Tagging_Model_Meta_Product $model */ $model = Mage::getModel('nosto_tagging/meta_product'); $model->setProductId($product->getId()); try { $op = new NostoOperationProduct($account); $op->addProduct($model); $op->delete(); } catch (NostoException $e) { Mage::log("\n" . $e, Zend_Log::ERR, 'nostotagging.log'); } } } return $this; }
/** * Sends a product delete API request to Nosto. * * @param Product $product the product that has been deleted. */ public function delete(Product $product) { if (!Validate::isLoadedObject($product) || in_array($product->id, self::$_processed_products)) { return; } self::$_processed_products[] = $product->id; foreach ($this->getAccountData() as $data) { list($account) = $data; $nosto_product = new NostoTaggingProduct(); $nosto_product->assignId($product); try { $op = new NostoOperationProduct($account); $op->addProduct($nosto_product); $op->delete(); } catch (NostoException $e) { Nosto::helper('nosto_tagging/logger')->error(__CLASS__ . '::' . __FUNCTION__ . ' - ' . $e->getMessage(), $e->getCode(), get_class($product), (int) $product->id); } } }