/** * Collects list of objects in product list * * @param Mage_Catalog_Block_Product_List_Upsell $object * @return Mage_Catalog_Model_Product[] */ public function collect($object) { $result = array(); $products = $object->getItems(); foreach ($products as $product) { $result[] = $product; } return $result; }
/** * Get crosssell items * * @return array */ public function getItemCollection() { if (!Mage::helper('conversionpro')->isActiveEngine() || !Mage::getStoreConfigFlag('conversionpro/crosssell_settings/upsell_enabled')) { return parent::getItemCollection(); } $items = $this->_items; if (is_null($items)) { reset($this->_itemCollection); $lastAdded = null; //This code path covers the 2 cases - product page and shopping cart if ($this->getProduct() != null) { $lastAdded = $this->getProduct()->getId(); } else { $cartProductIds = $this->_getCartProductIds(); $lastAdded = null; for ($i = count($cartProductIds) - 1; $i >= 0; $i--) { $id = $cartProductIds[$i]; $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($id); if (empty($parentIds)) { $lastAdded = $id; break; } } } $crossSellIds = Mage::helper('conversionpro')->getSalespersonCrossSellApi()->getRecommendationsIds($lastAdded); $this->_maxItemCount = Mage::getStoreConfig('conversionpro/crosssell_settings/upsell_limit'); $this->_itemCollection = $this->_getCollection()->addAttributeToFilter('entity_id', array('in' => $crossSellIds)); } return $this->_itemCollection; }
public function getAddToCartUrl($product, $additional = array()) { if ($this->helper('icart')->isEnabled()) { return $this->helper('icart')->getAddUrl($product, $additional); } else { return parent::getAddToCartUrl($product, $additional); } }
/** * Render html * Return empty string if module isn't enabled * * @return string */ protected function _toHtml() { if (!$this->_canBeShown()) { return ''; } return parent::_toHtml(); }
protected function _prepareData() { $limit = Mage::getStoreConfig('recommender/relatedproducts/numberofupsellproducts'); /* @var $product Mage_Catalog_Model_Product */ $product = Mage::registry('product'); // A bit of a hack, but return an empty collection if user selected 0 recommendations to show in config if ($limit < 1) { $this->_itemCollection = $product->getRelatedProductCollection(); $this->_itemCollection->load(); $this->_itemCollection->clear(); return $this; } // Get manual links // Set link source to automated CommerceStack recommendations $linkModel = $product->getLinkInstance(); $linkModel->useLinkSourceManual(); parent::_prepareData(); $unionLinkedItemCollection = $this->_itemCollection; $numRecsToGet = $limit; if (!is_null($unionLinkedItemCollection)) { $numRecsToGet = $limit - count($unionLinkedItemCollection); } if ($numRecsToGet > 0) { // Figure out if we should use a category filter $constrainCategory = Mage::getStoreConfig('recommender/relatedproducts/constraincategory'); $currentCategory = Mage::registry('current_category'); if (is_object($currentCategory)) { $productCategory = $currentCategory; } if (is_null($currentCategory)) { // This could be a recently viewed or a search page. Try to get category collection and arbitrarily use first /* @var $currentProduct Mage_Catalog_Model_Product */ $currentProduct = Mage::registry('current_product'); if (is_object($currentProduct)) { $currentCategory = $currentProduct->getCategoryCollection(); $productCategory = $currentCategory->getFirstItem(); $currentCategory = $productCategory; } } $useCategoryFilter = !is_null($currentCategory) && $constrainCategory; // Set link source to automated CommerceStack recommendations $linkModel = $product->getLinkInstance(); $linkModel->useLinkSourceCommerceStack(); $upsellSource = Mage::getStoreConfig('recommender/relatedproductsadvanced/upsellsource'); } while ($numRecsToGet > 0) { if ($upsellSource == 'related') { $linkedItemCollection = $product->getRelatedProductCollection()->addAttributeToSelect('required_options')->setGroupBy()->setPositionOrder()->addStoreFilter(); } elseif ($upsellSource == 'crosssell') { $linkedItemCollection = $product->getCrossSellProductCollection()->setGroupBy()->setPositionOrder()->addStoreFilter(); } $linkedItemCollection->getSelect()->limit($numRecsToGet); if ($useCategoryFilter) { $linkedItemCollection->addCategoryFilter($currentCategory); } if (!is_null($unionLinkedItemCollection)) { $linkedItemCollection->addExcludeProductFilter($unionLinkedItemCollection->getAllIds()); } Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($linkedItemCollection, Mage::getSingleton('checkout/session')->getQuoteId()); $this->_addProductAttributesAndPrices($linkedItemCollection); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($linkedItemCollection); $linkedItemCollection->load(); // Add new source linked items to existing union of linked items if (is_null($unionLinkedItemCollection)) { $unionLinkedItemCollection = $linkedItemCollection; } else { foreach ($linkedItemCollection as $linkedProduct) { $unionLinkedItemCollection->addItem($linkedProduct); } } if (!is_null($unionLinkedItemCollection)) { $numRecsToGet = $limit - count($unionLinkedItemCollection); } // Go up a category level for next iteration $currentCategory = $currentCategory->getParentCategory(); if (is_null($currentCategory->getId())) { break; } } // If we still don't have enough recommendations fill out the remaining with randoms. $currentCategory = $productCategory; while ($numRecsToGet > 0) { $randCollection = Mage::getResourceModel('catalog/product_collection'); Mage::getModel('catalog/layer')->prepareProductCollection($randCollection); $randCollection->getSelect()->order('rand()'); $randCollection->addStoreFilter(); $randCollection->setPage(1, $numRecsToGet); $randCollection->addIdFilter(array_merge($unionLinkedItemCollection->getAllIds(), array($product->getId())), true); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($randCollection); if ($useCategoryFilter) { $randCollection->addCategoryFilter($currentCategory); } foreach ($randCollection as $linkedProduct) { $unionLinkedItemCollection->addItem($linkedProduct); } if (!$useCategoryFilter) { break; } // We tried everything if (!is_null($unionLinkedItemCollection)) { $numRecsToGet = $limit - count($unionLinkedItemCollection); } // Go up a category level for next iteration $currentCategory = $currentCategory->getParentCategory(); if (is_null($currentCategory->getId())) { break; } } $this->_itemCollection = $unionLinkedItemCollection; /** * Updating collection with desired items */ Mage::dispatchEvent('catalog_product_upsell', array('product' => $product, 'collection' => $this->_itemCollection, 'limit' => $this->getItemLimit())); foreach ($this->_itemCollection as $product) { $product->setDoNotUseCategoryId(true); } // We need to reset the link source to manual here so as not to break // grouped products $linkModel->useLinkSourceManual(); return $this; }
/** * Constructor set the namespace for upsell */ public function __construct() { $this->jcUpsell = new Netresearch_JCarouselSlider_Block_Summary('jcupsells'); Mage_Catalog_Block_Product_List_Upsell::setItemLimit('upsell', $this->jcUpsell->getMaxItemCount()); }
/** * @param string $html * @param Mage_Catalog_Block_Product_List_Upsell $block * @return string */ private function _processViewedProducts($html, $block) { $helper = $this->_getHelper(); /** @var $processor Mageplace_Callforprice_Model_Htmlprocessor_Interface */ $processor = Mage::getModel('mageplace_callforprice/htmlprocessor_factory')->createProcessor(); $processor->load($html); if ($helper->isGlobalEnabled()) { $processor->replace($helper->getCssSelector('viewed_product_price'), $helper->prepareReplacement()); return $processor->getHtml(); } $processor->process('viewed', array('products' => $block->getItemsCollection())); return $processor->getHtml(); }