public function createIndexData(Mage_Catalog_Model_Product $object) { $searchEntityId = $object->getId(); $priceAttributeId = $this->getTierPriceAttribute()->getId(); if ($object->isGrouped()) { $priceAttributeId = $this->getPriceAttribute()->getId(); $associated = $object->getTypeInstance()->getAssociatedProducts(); $searchEntityId = array(); foreach ($associated as $product) { $searchEntityId[] = $product->getId(); } } if (!count($searchEntityId)) { return false; } $result = array(); $data = array(); $data['store_id'] = $object->getStoreId(); $data['entity_id'] = $object->getId(); $search['store_id'] = $object->getStoreId(); $search['entity_id'] = $searchEntityId; $search['attribute_id'] = $priceAttributeId; foreach ($this->_customerGroups as $group) { $search['customer_group_id'] = $group->getId(); $data['customer_group_id'] = $group->getId(); $value = $this->_getResource()->getMinimalValue($search); if (is_null($value)) { continue; } $data['value'] = $value; $result[] = $data; } return $result; }
/** * Purge product * * @param Mage_Catalog_Model_Product $product * @param bool $purgeParentProducts * @param bool $purgeCategories * @return Phoenix_VarnishCache_Model_Control_Catalog_Product */ public function purge(Mage_Catalog_Model_Product $product, $purgeParentProducts = false, $purgeCategories = false) { if ($this->_canPurge()) { $idsToPurge = array(); $categoryIdsToPurge = array(); $idsToPurge[] = $product->getId(); $this->_getSession()->addSuccess(Mage::helper('varnishcache')->__('Varnish cache for "%s" has been purged.', $product->getName())); if ($purgeParentProducts) { // purge parent products $productRelationCollection = $this->_getProductRelationCollection()->filterByChildId($product->getId()); foreach ($productRelationCollection as $productRelation) { $idsToPurge[] = $productRelation->getParentId(); } // purge categories of parent products if ($purgeCategories) { $categoryProductCollection = $this->_getCategoryProductRelationCollection()->filterAllByProductIds($productRelationCollection->getAllIds()); foreach ($categoryProductCollection as $categoryProduct) { $categoryIdsToPurge[] = $categoryProduct->getCategoryId(); } } } $this->_purgeByIds($idsToPurge); if ($purgeCategories) { foreach ($product->getCategoryCollection() as $category) { $categoryIdsToPurge[] = $category->getId(); } $this->_getSession()->addSuccess(Mage::helper('varnishcache')->__('Varnish cache for the product\'s categories has been purged.')); } $this->_purgeCategoriesByIds($categoryIdsToPurge); } return $this; }
/** * Save Product Links process * * @param Mage_Catalog_Model_Product $product * @param array $data * @param int $typeId * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link */ public function saveProductLinks($product, $data, $typeId) { if (!is_array($data)) { $data = array(); } $attributes = $this->getAttributesByType($typeId); $deleteCondition = $this->_getWriteAdapter()->quoteInto('product_id=?', $product->getId()) . $this->_getWriteAdapter()->quoteInto(' AND link_type_id=?', $typeId); $this->_getWriteAdapter()->delete($this->getMainTable(), $deleteCondition); foreach ($data as $linkedProductId => $linkInfo) { $this->_getWriteAdapter()->insert($this->getMainTable(), array('product_id' => $product->getId(), 'linked_product_id' => $linkedProductId, 'link_type_id' => $typeId)); $linkId = $this->_getWriteAdapter()->lastInsertId(); foreach ($attributes as $attributeInfo) { $attributeTable = $this->getAttributeTypeTable($attributeInfo['type']); if ($attributeTable && isset($linkInfo[$attributeInfo['code']])) { $this->_getWriteAdapter()->insert($attributeTable, array('product_link_attribute_id' => $attributeInfo['id'], 'link_id' => $linkId, 'value' => $linkInfo[$attributeInfo['code']])); } } } /** * Grouped product relations should be added to relation table */ if ($typeId == Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED) { } return $this; }
/** * Get product final price via configurable product's tier pricing structure. * Uses qty of parent item to determine price. * * @param Mage_Catalog_Model_Product $product * * @return float */ private function _calcConfigProductTierPricing($product) { $tierPrice = PHP_INT_MAX; if ($items = $this->_getAllVisibleItems()) { // map mapping the IDs of the parent products with the quantities of the corresponding simple products $idQuantities = array(); // go through all products in the quote foreach ($items as $item) { /** @var Mage_Sales_Model_Quote_Item $item */ if ($item->getParentItem()) { continue; } // this is the product ID of the parent! $id = $item->getProductId(); // map the parent ID with the quantity of the simple product $idQuantities[$id][] = $item->getQty(); } // compute the total quantity of items of the configurable product if (array_key_exists($product->getId(), $idQuantities)) { $totalQty = array_sum($idQuantities[$product->getId()]); $tierPrice = $product->getPriceModel()->getBasePrice($product, $totalQty); } } return $tierPrice; }
/** * @param Mage_Catalog_Model_Product $product */ public function __construct($params) { $this->_product = $params['product']; $this->_storeId = $params['store_id']; $this->_productId = $this->_product->getId(); $product = $this->_product = Mage::getModel('catalog/product')->setStoreId($this->_storeId)->load($this->_product->getId()); $this->setData($this->_createOffer()); }
public function testGetProduct() { $this->assertNotEmpty($this->_block->getProduct()->getId()); $this->assertEquals($this->_product->getId(), $this->_block->getProduct()->getId()); Mage::unregister('product'); $this->_block->setProductId(1); $this->assertEquals($this->_product->getId(), $this->_block->getProduct()->getId()); }
/** * Retrieve product attributes as xml object * * @param Mage_Catalog_Model_Product $product * @param string $itemNodeName * @return Mage_XmlConnect_Model_Simplexml_Element */ public function productToXmlObject(Mage_Catalog_Model_Product $product, $itemNodeName = 'item') { /** @var $item Mage_XmlConnect_Model_Simplexml_Element */ $item = Mage::getModel('xmlconnect/simplexml_element', '<' . $itemNodeName . '></' . $itemNodeName . '>'); if ($product && $product->getId()) { $item->addChild('entity_id', $product->getId()); $item->addChild('name', $item->escapeXml($product->getName())); $item->addChild('entity_type', $product->getTypeId()); $item->addChild('short_description', $item->escapeXml($product->getShortDescription())); $description = Mage::helper('xmlconnect')->htmlize($item->xmlentities($product->getDescription())); $item->addChild('description', $description); $item->addChild('link', $product->getProductUrl()); if ($itemNodeName == 'item') { $imageToResize = Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small'); $propertyToResizeName = 'small_image'; } else { $imageToResize = Mage::helper('xmlconnect/image')->getImageSizeForContent('product_big'); $propertyToResizeName = 'image'; } $icon = clone Mage::helper('catalog/image')->init($product, $propertyToResizeName)->resize($imageToResize); $iconXml = $item->addChild('icon', $icon); $file = Mage::helper('xmlconnect')->urlToPath($icon); $iconXml->addAttribute('modification_time', filemtime($file)); $item->addChild('in_stock', (int) $product->getIsInStock()); $item->addChild('is_salable', (int) $product->isSalable()); /** * By default all products has gallery (because of collection not load gallery attribute) */ $hasGallery = 1; if ($product->getMediaGalleryImages()) { $hasGallery = sizeof($product->getMediaGalleryImages()) > 0 ? 1 : 0; } $item->addChild('has_gallery', $hasGallery); /** * If product type is grouped than it has options as its grouped items */ if ($product->getTypeId() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE || $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) { $product->setHasOptions(true); } $item->addChild('has_options', (int) $product->getHasOptions()); if ($minSaleQty = $this->_getMinimalQty($product)) { $item->addChild('min_sale_qty', (int) $minSaleQty); } if (!$product->getRatingSummary()) { Mage::getModel('review/review')->getEntitySummary($product, Mage::app()->getStore()->getId()); } $item->addChild('rating_summary', round((int) $product->getRatingSummary()->getRatingSummary() / 10)); $item->addChild('reviews_count', $product->getRatingSummary()->getReviewsCount()); if ($this->getChild('product_price')) { $this->getChild('product_price')->setProduct($product)->setProductXmlObj($item)->collectProductPrices(); } if ($this->getChild('additional_info')) { $this->getChild('additional_info')->addAdditionalData($product, $item); } } return $item; }
public function open($product_id) { $this->_product = Mage::getModel('catalog/product')->load($product_id); if ($this->_product->getId()) { $this->url($this->_product->getProductUrl()); return $this; } throw new Exception("product not found"); }
public function beforeProcess() { $product = $this->getEvent()->getProduct(); if (!$product instanceof Mage_Catalog_Model_Product) { throw new Ess_M2ePro_Model_Exception('Product event doesn\'t have correct Product instance.'); } $this->product = $product; $this->productId = (int) $this->product->getId(); $this->storeId = (int) $this->product->getData('store_id'); }
/** * Return Product attribute by attribute's ID * * @param Mage_Catalog_Model_Product $product * @param int $attributeId * @return null|Mage_Catalog_Model_Entity_Attribute Product's attribute */ public function getProductAttribute(Mage_Catalog_Model_Product $product, $attributeId) { if (!isset($this->_productAttributes[$product->getId()])) { $attributes = $product->getAttributes(); foreach ($attributes as $attribute) { $this->_productAttributes[$product->getId()][$attribute->getAttributeId()] = $attribute; } } return isset($this->_productAttributes[$product->getId()][$attributeId]) ? $this->_productAttributes[$product->getId()][$attributeId] : null; }
/** * For a product get all the parent and children product ids when they are set * * @param Mage_Catalog_Model_Product $oProduct * @return int[] */ protected function getChildrenAndParentIds(Mage_Catalog_Model_Product $oProduct) { $oProductType = $oProduct->getTypeInstance(); $aLinkedProductIds = $oProductType->getParentIdsByChild($oProduct->getId()); $aChildProductIdsByGroups = $oProductType->getChildrenIds($oProduct->getId()); foreach ($aChildProductIdsByGroups as $aChildProductIds) { $aLinkedProductIds = array_unique(array_merge($aLinkedProductIds, $aChildProductIds)); } return $aLinkedProductIds; }
/** * @param Mage_Catalog_Model_Product $product * @param $productSubscriptionsData * @param $storeId * @throws Exception */ protected function _updateProductSubscriptions(Mage_Catalog_Model_Product $product, $productSubscriptionsData, $storeId) { if (!$productSubscriptionsData) { if ($product->getData('adyen_subscription_type') != Adyen_Subscription_Model_Product_Subscription::TYPE_DISABLED) { $product->setData('adyen_subscription_type', Adyen_Subscription_Model_Product_Subscription::TYPE_DISABLED); Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('adyen_subscription')->__('Adyen Subscription Type is set back to \'Disabled\' because no subscriptions were defined')); } return; } /** @var array $productSubscriptionIds */ $productSubscriptionCollection = Mage::getModel('adyen_subscription/product_subscription')->getCollection()->addFieldToFilter('product_id', $product->getId()); $isGlobal = Mage::app()->isSingleStoreMode(); if (!$isGlobal && (int) $storeId) { /** @var $website Mage_Core_Model_Website */ $website = Mage::app()->getStore($storeId)->getWebsite(); $productSubscriptionCollection->addFieldToFilter('website_id', $website->getId()); } $productSubscriptionIds = $productSubscriptionCollection->getAllIds(); $resource = Mage::getSingleton('core/resource'); $connection = $resource->getConnection('core_write'); $i = 1; // Save subscriptions foreach ($productSubscriptionsData as $id => $subscriptionData) { $subscription = Mage::getModel('adyen_subscription/product_subscription')->load($id); if (!$subscription->getId()) { $subscription->setProductId($product->getId()); } if (!isset($subscriptionData['use_default']) && $storeId) { // Save store label $labelData = array('label' => $subscriptionData['label'], 'subscription_id' => $subscription->getId(), 'store_id' => $storeId); $connection->insertOnDuplicate($resource->getTableName('adyen_subscription/product_subscription_label'), $labelData, array('label')); unset($subscriptionData['label']); } if (isset($subscriptionData['use_default']) && $storeId) { // Delete store label $connection->delete($resource->getTableName('adyen_subscription/product_subscription_label'), array('subscription_id = ?' => $subscription->getId(), 'store_id = ?' => $storeId)); } if ($subscriptionData['customer_group_id'] == '') { $subscriptionData['customer_group_id'] = null; } $subscription->addData($subscriptionData); $subscription->setSortOrder($i * 10); if (in_array($id, $productSubscriptionIds)) { $productSubscriptionIds = array_diff($productSubscriptionIds, array($id)); } $subscription->save(); $i++; } // Delete subscriptions foreach ($productSubscriptionIds as $subscriptionId) { Mage::getModel('adyen_subscription/product_subscription')->setId($subscriptionId)->delete(); } }
/** * Should return list of tags to clean * * @param Mage_Catalog_Model_Product $object * @return string[]|string */ protected function _collectTags($object) { // Clear category cache for new products if ($this->_isForUpdate && !$object->getId()) { $result = array(); foreach ($object->getCategoryIds() as $categoryId) { $result[] = EcomDev_Varnish_Model_Processor_Category::TAG_PREFIX . $categoryId; } return $result; } return self::TAG_PREFIX . $object->getId(); }
/** * get a collection of all related products * * @param Mage_Catalog_Model_Product $product * @return Mage_Catalog_Model_Resource_Product_Collection|bool */ public function getRelatedProductsCollection(Mage_Catalog_Model_Product $product) { if (!$product->getId()) { return false; } /** @var Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $productCollection */ $parentProductsCollection = Mage::getResourceModel('catalog/product_collection'); $parentProductsCollection->addAttributeToSelect('url_key'); $parentProductsCollection->joinField('relation', 'catalog/product_relation', 'parent_id', 'parent_id=entity_id', '{{table}}.child_id=' . $product->getId(), 'inner'); $parentProductsCollection->load(); $parentProductsCollection->addItem($product); return $parentProductsCollection; }
private function prepareStockItemObserver(Mage_Catalog_Model_Product $product) { /** @var $stockItem Mage_CatalogInventory_Model_Stock_Item */ $stockItem = Mage::getModel('cataloginventory/stock_item'); $stockItem->loadByProduct($product->getId())->setProductId($product->getId()); foreach ($product->getData('stock_item')->getData() as $key => $value) { $stockItem->setOrigData($key, $value); } $observer = new Varien_Event_Observer(); $observer->setEvent(new Varien_Event()); $observer->setData('item', $stockItem); return $observer; }
public function deleteProduct(Mage_Catalog_Model_Product $product, $deletingMode) { if ($deletingMode == Ess_M2ePro_Model_Listing::DELETING_MODE_NONE) { return; } $listingsProducts = $this->getListing()->getProducts(true, array('product_id' => (int) $product->getId())); if (count($listingsProducts) <= 0) { return; } foreach ($listingsProducts as $listingProduct) { if (!$listingProduct instanceof Ess_M2ePro_Model_Listing_Product) { return; } try { if ($deletingMode == Ess_M2ePro_Model_Listing::DELETING_MODE_STOP) { $listingProduct->isStoppable() && Mage::getModel('M2ePro/StopQueue')->add($listingProduct); } if ($deletingMode == Ess_M2ePro_Model_Listing::DELETING_MODE_STOP_REMOVE) { $listingProduct->isStoppable() && Mage::getModel('M2ePro/StopQueue')->add($listingProduct); $listingProduct->addData(array('status' => Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED))->save(); $listingProduct->deleteInstance(); } } catch (Exception $exception) { } } }
/** * Retrieve url for add product to cart * * @param Mage_Catalog_Model_Product $product * @return string */ public function getAddUrl($product, $additional = array()) { /** * Identify continue shopping url */ // if ($currentProduct = AO::registry('current_product')) { // /** // * go to product view page // */ // $continueShoppingUrl = $currentProduct->getProductUrl(); // } elseif ($currentCategory = AO::registry('current_category')) { // /** // * go to category view page // */ // // $continueShoppingUrl = $currentCategory->getUrl().(count($this->_getRequest()->getQuery())!=0?'?'.http_build_qu//ery($this->_getRequest()->getQuery(), '', '&'):''); // // } else { // $continueShoppingUrl = $this->_getUrl('*/*/*', array('_current'=>true)); // } $continueShoppingUrl = $this->getCurrentUrl(); $params = array(Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => AO::helper('core')->urlEncode($continueShoppingUrl), 'product' => $product->getId()); if ($this->_getRequest()->getRouteName() == 'checkout' && $this->_getRequest()->getControllerName() == 'cart') { $params['in_cart'] = 1; } if (count($additional)) { $params = array_merge($params, $additional); } return $this->_getUrl('checkout/cart/add', $params); }
/** * Put the gallery value into the document collection * * @param Mage_Catalog_Model_Product $product The product we want to save the gallery for * @param string $attributeCode The attribute code of the saved gallery * @param array $savedGallery The content of the gallery to be saved * * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media Self reference */ public function saveGallery($product, $attributeCode, $savedGallery) { $updateFilter = array('_id' => new MongoInt32($product->getId())); $updateValue = array('galleries.' . $attributeCode => array_values($savedGallery)); $this->_getDocumentCollection()->update($updateFilter, array('$set' => $updateValue)); return $this; }
/** * Save configurable product relations * * @param Mage_Catalog_Model_Product|int $mainProduct the parent id * @param array $productIds the children id array * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable */ public function saveProducts($mainProduct, $productIds) { $isProductInstance = false; if ($mainProduct instanceof Mage_Catalog_Model_Product) { $mainProductId = $mainProduct->getId(); $isProductInstance = true; } else { $mainProductId = $mainProduct; } $select = $this->_getReadAdapter()->select()->from($this->getMainTable(), 'product_id')->where('parent_id=?', $mainProductId); $old = $this->_getReadAdapter()->fetchCol($select); $insert = array_diff($productIds, $old); $delete = array_diff($old, $productIds); if ((!empty($insert) || !empty($delete)) && $isProductInstance) { $mainProduct->setIsRelationsChanged(true); } if (!empty($delete)) { $where = join(' AND ', array($this->_getWriteAdapter()->quoteInto('parent_id=?', $mainProductId), $this->_getWriteAdapter()->quoteInto('product_id IN(?)', $delete))); $this->_getWriteAdapter()->delete($this->getMainTable(), $where); } if (!empty($insert)) { $data = array(); foreach ($insert as $childId) { $data[] = array('product_id' => $childId, 'parent_id' => $mainProductId); } $this->_getWriteAdapter()->insertMultiple($this->getMainTable(), $data); } // configurable product relations should be added to relation table Mage::getResourceSingleton('catalog/product_relation')->processRelations($mainProductId, $productIds); return $this; }
/** * Retrieve url for add product to cart * * @param Mage_Catalog_Model_Product $product * @return string */ public function getAddUrl($product, $additional = array()) { /** * Identify continue shopping url */ if ($currentProduct = Mage::registry('current_product')) { /** * go to product view page */ $continueShoppingUrl = $currentProduct->getProductUrl(); } elseif ($currentCategory = Mage::registry('current_category')) { /** * go to category view page */ $continueShoppingUrl = $currentCategory->getCategoryUrl(); } else { $continueShoppingUrl = $this->_getUrl('*/*/*', array('_current' => true)); } $params = array(Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => Mage::helper('core')->urlEncode($continueShoppingUrl), 'product' => $product->getId()); if ($this->_getRequest()->getModuleName() == 'checkout' && $this->_getRequest()->getControllerName() == 'cart') { $params['in_cart'] = 1; } if (count($additional)) { $params = array_merge($params, $additional); } return $this->_getUrl('checkout/cart/add', $params); }
/** * @param Mage_Catalog_Model_Product $productModel * @return Ess_M2ePro_Model_MagentoProduct */ public function setProduct(Mage_Catalog_Model_Product $productModel) { $this->_productModel = $productModel; $this->setProductId($this->_productModel->getId()); $this->setStoreId($this->_productModel->getStoreId()); return $this; }
/** * Initialize product view layout * * @param Mage_Catalog_Model_Product $product * @return Mage_Catalog_ProductController */ protected function _initProductLayout($product) { $update = $this->getLayout()->getUpdate(); $update->addHandle('default'); $this->addActionLayoutHandles(); $update->addHandle('PRODUCT_TYPE_' . $product->getTypeId()); $update->addHandle('PRODUCT_' . $product->getId()); if ($product->getPageLayout()) { $this->getLayout()->helper('page/layout')->applyHandle($product->getPageLayout()); } $this->loadLayoutUpdates(); $update->addUpdate($product->getCustomLayoutUpdate()); $this->generateLayoutXml()->generateLayoutBlocks(); if ($product->getPageLayout()) { $this->getLayout()->helper('page/layout')->applyTemplate($product->getPageLayout()); } $currentCategory = Mage::registry('current_category'); if ($root = $this->getLayout()->getBlock('root')) { $root->addBodyClass('product-' . $product->getUrlKey()); if ($currentCategory instanceof Mage_Catalog_Model_Category) { $root->addBodyClass('categorypath-' . $currentCategory->getUrlPath())->addBodyClass('category-' . $currentCategory->getUrlKey()); } } return $this; }
public function createIndexData(Mage_Catalog_Model_Product $object, Mage_Eav_Model_Entity_Attribute_Abstract $attribute = null) { $data = array(); $data['store_id'] = $attribute->getStoreId(); $data['entity_id'] = $object->getId(); $data['attribute_id'] = $attribute->getId(); $result = array(); $values = $object->getData($attribute->getAttributeCode()); if (!is_array($values)) { return $result; } foreach ($values as $row) { if (isset($row['delete']) && $row['delete']) { continue; } $data['qty'] = $row['price_qty']; $data['value'] = $row['price']; if ($row['cust_group'] == Mage_Customer_Model_Group::CUST_GROUP_ALL) { foreach ($this->_customerGroups as $group) { $data['customer_group_id'] = $group->getId(); $result[] = $data; } } else { $data['customer_group_id'] = $row['cust_group']; $result[] = $data; } } return $result; }
/** * Load gallery images for product * * @param Mage_Catalog_Model_Product $product * @param Mage_Catalog_Model_Product_Attribute_Backend_Media $object * @return array */ public function loadGallery($product, $object) { // Select gallery images for product $select = $this->_getReadAdapter()->select()->from(array('main' => $this->getMainTable()), array('value_id', 'value AS file'))->joinLeft(array('value' => $this->getTable(self::GALLERY_VALUE_TABLE)), 'main.value_id=value.value_id AND value.store_id=' . (int) $product->getStoreId(), array('label', 'position', 'disabled'))->joinLeft(array('default_value' => $this->getTable(self::GALLERY_VALUE_TABLE)), 'main.value_id=default_value.value_id AND default_value.store_id=0', array('label_default' => 'label', 'position_default' => 'position', 'disabled_default' => 'disabled'))->where('main.attribute_id = ?', $object->getAttribute()->getId())->where('main.entity_id = ?', $product->getId())->order('IF(value.position IS NULL, default_value.position, value.position) ASC'); $result = $this->_getReadAdapter()->fetchAll($select); $this->_removeDuplicates($result); return $result; }
public function handleAddResponse(Mage_Catalog_Model_Product $product, Mage_Core_Controller_Request_Http $request, Mage_Core_Controller_Response_Http $response) { $output = array('product_id' => $product->getId(), 'product_price' => $product->getFinalPrice(), 'product_image' => (string) Mage::helper('catalog/image')->init($product, 'image')->resize(150, 150), 'product_qty' => 1, 'quote_total' => $this->_getQuote()->getSubtotal(), 'quote_qty' => $this->_getQuote()->getItemsQty(), 'success' => true); $transport = new Varien_Object($output); $this->_retrieveHtmlResponse($transport); Mage::dispatchEvent('swiftotter_addtocart_success_output', array('transport' => $transport)); $this->_send($response, $transport->getData(), 200); }
/** * Retrieve url for new review creation * * @param Mage_Catalog_Model_Product $product * @return string */ public function getNewUrl($product) { $params = array('id' => $product->getId()); if ($product->getCategoryId()) { $params['category'] = $product->getCategoryId(); } return $this->_getUrl('review/product/list', $params); }
/** * @return Mage_CatalogInventory_Model_Stock_Item * @throws Ess_M2ePro_Model_Exception */ public function getStockItem() { if (is_null($this->_productModel) && $this->_productId < 0) { throw new Ess_M2ePro_Model_Exception('Load instance first'); } $productId = !is_null($this->_productModel) ? $this->_productModel->getId() : $this->_productId; return Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId); }
protected function modifyProduct(\Mage_Catalog_Model_Product $product, \Zend_Config $settings) { foreach ($settings as $attribute => $value) { $product->setData($attribute, $value); Logger::log('* change attribute <comment>%s</comment> of product #%d: "%s"', array($attribute, $product->getId(), $value)); } $product->save(); }
/** * Filter the collection by a product ID * * @param Mage_Catalog_Model_Product $product * @param int $storeId = null * @return $this */ public function addProductFilter(Mage_Catalog_Model_Product $product, $storeId = null) { if (is_null($storeId)) { $storeId = Mage::app()->getStore()->getId(); } $this->getSelect()->join(array('_product_filter' => $this->getTable('catalog/product_index_eav')), "`_product_filter`.`attribute_id`= `_attribute_table`.`attribute_id` AND `_product_filter`.`value` = `main_table`.`option_id`" . $this->getConnection()->quoteInto(" AND `_product_filter`.`entity_id` = ?", $product->getId()) . $this->getConnection()->quoteInto(" AND `_product_filter`.`store_id`=? ", $storeId), ''); return $this; }
/** * Retrieve a collection of post's associated with the given product * * @param Mage_Catalog_Model_Product $product * @return false|Fishpig_Wordpress_Model_Resource_Post_Collection_Abstract */ public function getAssociatedPostsByProduct(Mage_Catalog_Model_Product $product) { if (!$product instanceof Mage_Catalog_Model_Product) { return false; } $associations = array_keys($this->getAssociations('product/post', $product->getId())); $categoryAssociations = array_keys($this->getAssociations('product/category', $product->getId())); $associations = array_merge($associations, $this->_convertWpCategoryIds($categoryAssociations)); foreach ($product->getCategoryIds() as $categoryId) { $associations = array_merge($associations, array_keys($this->getAssociations('category/post', $categoryId))); $categoryAssociations = array_keys($this->getAssociations('category/category', $categoryId)); $associations = array_merge($associations, $this->_convertWpCategoryIds($categoryAssociations)); } if (count($associations) > 0) { return Mage::getResourceModel('wordpress/post_collection')->addFieldToFilter('ID', array('IN' => $associations))->addIsPublishedFilter(); } return false; }