public function validate(Varien_Object $object) { // for optimization if we no conditions if (!$this->getConditions()) { return true; } $origProduct = null; if ($object->getHasChildren() && $object->getProductType() == 'configurable') { //remember original product $origProduct = $object->getProduct(); $origSku = $object->getSku(); foreach ($object->getChildren() as $child) { // only one itereation. $categoryIds = array_merge($child->getProduct()->getCategoryIds(), $origProduct->getCategoryIds()); $categoryIds = array_unique($categoryIds); $object->setProduct($child->getProduct()); $object->setSku($child->getSku()); $object->getProduct()->setCategoryIds($categoryIds); } } $result = @Mage_Rule_Model_Condition_Combine::validate($object); if ($origProduct) { // restore original product $object->setProduct($origProduct); $object->setSku($origSku); } return $result; }
/** * Validate a condition with the checking of the child value * @param Varien_Object $object * * @return bool */ 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 && $this->validate($children[0]); } return $valid; }