Magento tidak mendukung ini secara default. Sebagai gantinya, kami mengalahkan Mage_SalesRule_Model_Validator dan membuat penulisan ulang aturan penjualan. Dalam hal itu kami memeriksa untuk melihat apakah produk terkait cocok dengan aturan penjualan.
app / code / local / AAA / SalesRule / etc / config.xml
<?xml version="1.0"?>
<config>
<modules>
<AAA_SalesRule>
<version>0.1.0</version>
</AAA_SalesRule>
</modules>
<global>
<models>
<aaa_salesrule>
<class>AAA_SalesRule_Model</class>
</aaa_salesrule>
<salesrule>
<rewrite>
<validator>AAA_SalesRule_Model_SalesRule_Validator</validator>
</rewrite>
</salesrule>
</models>
</global>
</config>
app / kode / lokal / AAA / SalesRule / Model / SalesRule / Validator.php
private function _hasChildInCart($product) {
$quote = Mage::getSingleton('checkout/session')->getQuote();
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
$childrenIds = $this->_getChildrenIds($childProducts);
foreach ($quote->getAllItems() as $item) {
if (in_array($item->getProductId(), $childrenIds)) {
$registeredItem = Mage::registry('rule_config_product_' . $product->getId());
if ($registeredItem != null && $registeredItem->getId() != $item->getId()) {
Mage::unregister('rule_config_product_' . $product->getId());
}
if ($registeredItem == null) {
Mage::register('rule_config_product_' . $product->getId(), $item);
}
return true;
}
}
return false;
}
private function _getChildrenIds($childProducts) {
$childrenIds = array();
foreach ($childProducts as $child) {
$childrenIds[] = $child->getId();
}
return $childrenIds;
}