# MUST PATCH for Magento version >= 1.9.2.0
http://magento.stackexchange.com/questions/53699/fatal-error-when-adding-configurable-product-in-cart-and-using-products-subsele
https://gist.github.com/tux-rampage/4d318ef516c8f4b2cf7e#file-luka-mce20151203-salesrule-hotfix-patch
### Example
app/code/local/Mage/SalesRule/Model/Rule/Condition/Product/Combine.php
```
public function validate(Varien_Object $object)
{
/** @var Mage_Catalog_Model_Product $product */
$product = $object->getProduct();
if (!($product instanceof Mage_Catalog_Model_Product)) {
$product = Mage::getModel('catalog/product')->load($object->getProductId());
}
$valid = parent::validate($object);
if (!$valid && $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {
$children = $object->getChildren();
$valid = $children && self::validate($children[0]);
}
return $valid;
}
```
web/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php
```
public function validate(Varien_Object $object)
{
if (!$this->getConditions()) {
return false;
}
// $value = $this->getValue();
// $aggregatorArr = explode('/', $this->getAggregator());
// $this->setValue((int)$aggregatorArr[0])->setAggregator($aggregatorArr[1]);
// The parent class is passing children of configurable items to this method again
// this is causing an infinite recursion if we let it pass
if ($object->getParentItemId()) {
return parent::validate($object);
}
$attr = $this->getAttribute();
$total = 0;
foreach ($object->getQuote()->getAllVisibleItems() as $item) {
if (parent::validate($item)) {
$total += $item->getData($attr);
}
}
// $this->setAggregator(join('/', $aggregatorArr))->setValue($value);
return $this->validateAttribute($total);
}
```
http://magento.stackexchange.com/questions/53699/fatal-error-when-adding-configurable-product-in-cart-and-using-products-subsele
https://gist.github.com/tux-rampage/4d318ef516c8f4b2cf7e#file-luka-mce20151203-salesrule-hotfix-patch
### Example
app/code/local/Mage/SalesRule/Model/Rule/Condition/Product/Combine.php
```
public function validate(Varien_Object $object)
{
/** @var Mage_Catalog_Model_Product $product */
$product = $object->getProduct();
if (!($product instanceof Mage_Catalog_Model_Product)) {
$product = Mage::getModel('catalog/product')->load($object->getProductId());
}
$valid = parent::validate($object);
if (!$valid && $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {
$children = $object->getChildren();
$valid = $children && self::validate($children[0]);
}
return $valid;
}
```
web/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php
```
public function validate(Varien_Object $object)
{
if (!$this->getConditions()) {
return false;
}
// $value = $this->getValue();
// $aggregatorArr = explode('/', $this->getAggregator());
// $this->setValue((int)$aggregatorArr[0])->setAggregator($aggregatorArr[1]);
// The parent class is passing children of configurable items to this method again
// this is causing an infinite recursion if we let it pass
if ($object->getParentItemId()) {
return parent::validate($object);
}
$attr = $this->getAttribute();
$total = 0;
foreach ($object->getQuote()->getAllVisibleItems() as $item) {
if (parent::validate($item)) {
$total += $item->getData($attr);
}
}
// $this->setAggregator(join('/', $aggregatorArr))->setValue($value);
return $this->validateAttribute($total);
}
```
Comments
Post a Comment