/** * Prepare inventory data from custom attribute * * @param Mage_Catalog_Model_Product $object * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract|void */ public function beforeSave($object) { $stockData = $object->getData($this->getAttribute()->getAttributeCode()); if (isset($stockData['qty']) && $stockData['qty'] === '') { $stockData['qty'] = null; } if ($object->getStockData() !== null || $stockData !== null) { $object->setStockData(array_replace((array) $object->getStockData(), (array) $stockData)); } $object->unsetData($this->getAttribute()->getAttributeCode()); parent::beforeSave($object); }
/** * Obtain final price of selection in a bundle product * * @param Mage_Catalog_Model_Product_Configuration_Item_Interface $item * @param Mage_Catalog_Model_Product $selectionProduct * * @return decimal */ public function getSelectionFinalPrice(Mage_Catalog_Model_Product_Configuration_Item_Interface $item, $selectionProduct) { $selectionProduct->unsetData('final_price'); return $item->getProduct()->getPriceModel()->getSelectionFinalTotalPrice($item->getProduct(), $selectionProduct, $item->getQty() * 1, $this->getSelectionQty($item->getProduct(), $selectionProduct->getSelectionId()), false, true); }
public function testIsSalable() { $this->_product->unsetData('is_salable'); $this->assertTrue($this->_model->isSalable($this->_product)); }
/** * Generates url for a product * * @param Mage_Catalog_Model_Product $product * @param Mage_Core_Model_Store $store * * @return string the url. */ public function generateProductUrl(Mage_Catalog_Model_Product $product, Mage_Core_Model_Store $store) { // Unset the cached url first, as it won't include the `___store` param // if it's cached. We need to define the specific store view in the url // in case the same domain is used for all sites. $product->unsetData('url'); /** @var Nosto_Tagging_Helper_Data $helper */ $helper = Mage::helper('nosto_tagging'); $url_params = array('_nosid' => true, '_ignore_category' => true, '_store' => $store->getId(), '_store_to_url' => true); $product_url = $product->getUrlInStore($url_params); if ($helper->getUsePrettyProductUrls($store)) { $product_url = $this->removeQueryParamFromUrl($product_url, '___store'); } return $product_url; }
/** * Builds the absolute store front url for the product page. * * The url includes the "___store" GET parameter in order for the Nosto * crawler to distinguish between stores that do not have separate domains * or paths. * * @param Mage_Catalog_Model_Product $product the product model. * @param Mage_Core_Model_Store $store the store model. * * @return string */ protected function buildUrl(Mage_Catalog_Model_Product $product, Mage_Core_Model_Store $store) { // Unset the cached url first, as it won't include the `___store` param // if it's cached. We need to define the specific store view in the url // in case the same domain is used for all sites. $product->unsetData('url'); return $product->getUrlInStore(array('_nosid' => true, '_ignore_category' => true, '_store' => $store->getCode())); }
/** * Loads the product info from a Magento product model. * * @param Mage_Catalog_Model_Product $product the product model. * @param Mage_Core_Model_Store|null $store the store to get the product data for. */ public function loadData(Mage_Catalog_Model_Product $product, Mage_Core_Model_Store $store = null) { if (is_null($store)) { $store = Mage::app()->getStore(); } // Unset the cached url first, as it won't include the `___store` param // if it's cached. We need to define the specific store view in the url // in case the same domain is used for all sites. $this->_url = $product->unsetData('url')->getUrlInStore(array('_nosid' => true, '_ignore_category' => true, '_store' => $store->getCode())); $this->_productId = $product->getId(); $this->_name = $product->getName(); $this->_imageUrl = $this->buildImageUrl($product, $store); $this->_price = Mage::helper('tax')->getPrice($product, Mage::helper('nosto_tagging/price')->getProductFinalPrice($product), true); $this->_listPrice = Mage::helper('tax')->getPrice($product, Mage::helper('nosto_tagging/price')->getProductPrice($product), true); $this->_currencyCode = $store->getCurrentCurrencyCode(); $this->_availability = $product->isAvailable() ? self::PRODUCT_IN_STOCK : self::PRODUCT_OUT_OF_STOCK; if (Mage::helper('core')->isModuleEnabled('Mage_Tag')) { $tagCollection = Mage::getModel('tag/tag')->getCollection()->addPopularity()->addStatusFilter(Mage_Tag_Model_Tag::STATUS_APPROVED)->addProductFilter($product->getId())->setFlag('relation', true)->addStoreFilter($store->getId())->setActiveFilter(); foreach ($tagCollection as $tag) { $this->_tags[] = $tag->getName(); } } if (!$product->canConfigure()) { $this->_tags[] = self::PRODUCT_ADD_TO_CART; } $this->_categories = $this->getProductCategories($product); $this->_shortDescription = (string) $product->getShortDescription(); $this->_description = (string) $product->getDescription(); $this->_brand = $product->getManufacturer() ? (string) $product->getAttributeText('manufacturer') : ''; $this->_datePublished = $product->getCreatedAt(); }
/** * Update product url key * * @param Mage_Catalog_Model_Product $product * @param string $newUrlKey * @param int $storeId */ function processProduct($product, $newUrlKey, $storeId) { $store = Mage::app()->getStore(); Mage::app()->setCurrentStore(Mage::app()->getStore(0)); if (!$this->isEntityProcessed(self::ENTITY_TYPE_PRODUCT, $product->getId() . '-' . $storeId) && !preg_match('~-[a-f0-9]{32}$~i', $newUrlKey)) { $product->setStoreId($storeId ? $storeId : null); $product->setUrlKey($newUrlKey . '-' . md5($product->getStoreId() . $product->getId())); $product->save(); $this->_reindexProduct($product->getId()); $product->unsetData('request_path'); $product->unsetData('url'); $this->markEntityProcessed(self::ENTITY_TYPE_PRODUCT, $product->getId() . '-' . $product->getStoreId()); } Mage::app()->setCurrentStore($store); }