Version Notes
Tested in Magento 1.5 - 1.7.0.2
Download this release
Release Info
| Developer | James Harrison |
| Extension | Bliss_Crosssellcategory |
| Version | 1.0.0.0 |
| Comparing to | |
| See all releases | |
Version 1.0.0.0
- app/code/community/Bliss/Crosssellcategory/Block/.DS_Store +0 -0
- app/code/community/Bliss/Crosssellcategory/Block/Cart/Crosssell.php +98 -0
- app/code/community/Bliss/Crosssellcategory/etc/config.xml +20 -0
- app/code/community/Bliss/Crosssellcategory/etc/system.xml +30 -0
- app/etc/modules/Bliss_Crosssellcategory.xml +12 -0
- package.xml +19 -0
app/code/community/Bliss/Crosssellcategory/Block/.DS_Store
ADDED
|
Binary file
|
app/code/community/Bliss/Crosssellcategory/Block/Cart/Crosssell.php
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Cart crosssell list with category override option
|
| 4 |
+
*
|
| 5 |
+
* @category Bliss
|
| 6 |
+
* @package Bliss_Crosssellcategory
|
| 7 |
+
* @author James Harrison <james@blissmedia.com.au>
|
| 8 |
+
*/
|
| 9 |
+
class Bliss_Crosssellcategory_Block_Cart_Crosssell extends Mage_Checkout_Block_Cart_Crosssell
|
| 10 |
+
{
|
| 11 |
+
|
| 12 |
+
const XML_PATH_CROSSSELL_USE_CATEGORY = 'checkout/cart/crosssell_use_category';
|
| 13 |
+
const XML_PATH_CROSSSELL_CATEGORY_ID = 'checkout/cart/crosssell_category_id';
|
| 14 |
+
|
| 15 |
+
/**
|
| 16 |
+
* Get crosssell items
|
| 17 |
+
*
|
| 18 |
+
* @return array
|
| 19 |
+
*/
|
| 20 |
+
public function getItems()
|
| 21 |
+
{
|
| 22 |
+
/** @var $category Mage_Catalog_Model_Category */
|
| 23 |
+
$categoryId = $this->_getOverrideCategoryId();
|
| 24 |
+
$category = Mage::getModel('catalog/category');
|
| 25 |
+
|
| 26 |
+
//return normal cross-sell collection if this feature is turned off or category doesn't exist.
|
| 27 |
+
if(!Mage::getStoreConfig(self::XML_PATH_CROSSSELL_USE_CATEGORY)
|
| 28 |
+
|| !$category->checkId($categoryId)) return parent::getItems();
|
| 29 |
+
|
| 30 |
+
$items = $this->getData('items');
|
| 31 |
+
if (is_null($items)) {
|
| 32 |
+
$items = array();
|
| 33 |
+
$ninProductIds = $this->_getCartProductIds();
|
| 34 |
+
if ($ninProductIds) {
|
| 35 |
+
$lastAdded = (int) $this->_getLastAddedProductId();
|
| 36 |
+
if ($lastAdded) {
|
| 37 |
+
$collection = $this->_getOverrideCollection()
|
| 38 |
+
->addIdFilter($lastAdded, true);
|
| 39 |
+
if (!empty($ninProductIds)) {
|
| 40 |
+
$collection->addIdFilter($ninProductIds, true);
|
| 41 |
+
}
|
| 42 |
+
$collection->load();
|
| 43 |
+
|
| 44 |
+
foreach ($collection as $item) {
|
| 45 |
+
$ninProductIds[] = $item->getId();
|
| 46 |
+
$items[] = $item;
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
if (count($items) < $this->_maxItemCount) {
|
| 51 |
+
$filterProductIds = array_merge($this->_getCartProductIds(), $this->_getCartProductIdsRel());
|
| 52 |
+
$collection = $this->_getOverrideCollection()
|
| 53 |
+
->addIdFilter($ninProductIds,true)
|
| 54 |
+
->setPageSize($this->_maxItemCount-count($items))
|
| 55 |
+
->load();
|
| 56 |
+
foreach ($collection as $item) {
|
| 57 |
+
$items[] = $item;
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
$this->setData('items', $items);
|
| 64 |
+
}
|
| 65 |
+
return $items;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
/**
|
| 69 |
+
* Get crosssell products collection
|
| 70 |
+
*
|
| 71 |
+
* @return Mage_Catalog_Model_Resource_Product_Collection
|
| 72 |
+
*/
|
| 73 |
+
protected function _getOverrideCollection()
|
| 74 |
+
{
|
| 75 |
+
/** @var $category Mage_Catalog_Model_Category */
|
| 76 |
+
$categoryId = $this->_getOverrideCategoryId();
|
| 77 |
+
$category = Mage::getModel('catalog/category');
|
| 78 |
+
|
| 79 |
+
$category->load($categoryId);
|
| 80 |
+
/** @var $collection Mage_Catalog_Model_Resource_Product_Collection */
|
| 81 |
+
$collection = $category->getProductCollection()
|
| 82 |
+
->setStoreId(Mage::app()->getStore()->getId())
|
| 83 |
+
->addStoreFilter()
|
| 84 |
+
->setPageSize($this->_maxItemCount);
|
| 85 |
+
$this->_addProductAttributesAndPrices($collection);
|
| 86 |
+
|
| 87 |
+
Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
|
| 88 |
+
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
|
| 89 |
+
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
|
| 90 |
+
|
| 91 |
+
return $collection;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
protected function _getOverrideCategoryId() {
|
| 96 |
+
return Mage::getStoreConfig(self::XML_PATH_CROSSSELL_CATEGORY_ID);
|
| 97 |
+
}
|
| 98 |
+
}
|
app/code/community/Bliss/Crosssellcategory/etc/config.xml
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Bliss_Crosssellcategory>
|
| 5 |
+
<version>1.0.0.0</version>
|
| 6 |
+
</Bliss_Crosssellcategory>
|
| 7 |
+
</modules>
|
| 8 |
+
<global>
|
| 9 |
+
<blocks>
|
| 10 |
+
<crosssellcategory>
|
| 11 |
+
<class>Bliss_Crosssellcategory_Block</class>
|
| 12 |
+
</crosssellcategory>
|
| 13 |
+
<checkout>
|
| 14 |
+
<rewrite>
|
| 15 |
+
<cart_crosssell>Bliss_Crosssellcategory_Block_Cart_Crosssell</cart_crosssell>
|
| 16 |
+
</rewrite>
|
| 17 |
+
</checkout>
|
| 18 |
+
</blocks>
|
| 19 |
+
</global>
|
| 20 |
+
</config>
|
app/code/community/Bliss/Crosssellcategory/etc/system.xml
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<sections>
|
| 4 |
+
<checkout>
|
| 5 |
+
<groups>
|
| 6 |
+
<cart>
|
| 7 |
+
<fields>
|
| 8 |
+
<crosssell_use_category translate="label">
|
| 9 |
+
<label>Use category for cross-sell products?</label>
|
| 10 |
+
<frontend_type>select</frontend_type>
|
| 11 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 12 |
+
<sort_order>1</sort_order>
|
| 13 |
+
<show_in_default>1</show_in_default>
|
| 14 |
+
<show_in_website>1</show_in_website>
|
| 15 |
+
<show_in_store>1</show_in_store>
|
| 16 |
+
</crosssell_use_category>
|
| 17 |
+
<crosssell_category_id translate="label">
|
| 18 |
+
<label>Category ID for cross-sell products</label>
|
| 19 |
+
<frontend_type>text</frontend_type>
|
| 20 |
+
<sort_order>2</sort_order>
|
| 21 |
+
<show_in_default>1</show_in_default>
|
| 22 |
+
<show_in_website>1</show_in_website>
|
| 23 |
+
<show_in_store>1</show_in_store>
|
| 24 |
+
</crosssell_category_id>
|
| 25 |
+
</fields>
|
| 26 |
+
</cart>
|
| 27 |
+
</groups>
|
| 28 |
+
</checkout>
|
| 29 |
+
</sections>
|
| 30 |
+
</config>
|
app/etc/modules/Bliss_Crosssellcategory.xml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Bliss_Crosssellcategory>
|
| 5 |
+
<active>true</active>
|
| 6 |
+
<codePool>community</codePool>
|
| 7 |
+
<depends>
|
| 8 |
+
<Mage_Checkout />
|
| 9 |
+
</depends>
|
| 10 |
+
</Bliss_Crosssellcategory>
|
| 11 |
+
</modules>
|
| 12 |
+
</config>
|
package.xml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>Bliss_Crosssellcategory</name>
|
| 4 |
+
<version>1.0.0.0</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license>GPL</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>A simple extension that lets users display products from a particular category on the cart page in place of the usual crosssell products.
|
| 10 |
+
</summary>
|
| 11 |
+
<description>Manually assigning crosssell products in your catalog can be time consuming - this extension lets you use products from a designated category instead.</description>
|
| 12 |
+
<notes>Tested in Magento 1.5 - 1.7.0.2</notes>
|
| 13 |
+
<authors><author><name>James Harrison</name><user>jharrisonau</user><email>jharrison.au@gmail.com</email></author></authors>
|
| 14 |
+
<date>2013-02-11</date>
|
| 15 |
+
<time>04:54:57</time>
|
| 16 |
+
<contents><target name="magecommunity"><dir name="Bliss"><dir name="Crosssellcategory"><dir name="Block"><dir name="Cart"><file name="Crosssell.php" hash="dbf493b3b44342f6efe19940135ab53d"/></dir><file name=".DS_Store" hash="14afb1a1943dbda5e10352e586a0761b"/></dir><dir name="etc"><file name="config.xml" hash="321648697b3e8aaaf9e95a3efea8b035"/><file name="system.xml" hash="499322e216b75d37f8a737e31269afe8"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Bliss_Crosssellcategory.xml" hash="34e1fc59aa8fd2b5b00846d9feeb4ad6"/></dir></target></contents>
|
| 17 |
+
<compatible/>
|
| 18 |
+
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Checkout</name><channel>community</channel><min></min><max></max></package></required></dependencies>
|
| 19 |
+
</package>
|
