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 Product Rule Condition * * @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()); } $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal()); $valid = parent::validate($product); if (!$valid && $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) { $children = $object->getChildren(); $valid = $children && $this->validate($children[0]); } return $valid; }
/** * Get children of specified item * * @param Varien_Object $item * @return array */ public function getMultipleRows($item) { return $item->getChildren(); }
/** * Has children of specified item * * @param Varien_Object $item * @return bool */ public function hasMultipleRows($item) { return $item->hasChildren() && count($item->getChildren()) > 0; }
/** * Deprecated since 1.1.7 * * @param Varien_Object $object * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category */ protected function _saveCountChidren($object) { $chidren = $object->getChildren(); if (strlen($chidren) > 0) { $chidrenCount = count(explode(',', $chidren)); } else { $chidrenCount = 0; } $this->_getWriteAdapter()->update($this->getEntityTable(), array('children_count' => $chidrenCount), $this->_getWriteAdapter()->quoteInto('entity_id=?', $object->getId())); return $this; }
/** * Retrives frame object * @param Varien_Object $object Category Tree Node * @return Varien_Object */ protected function _getFrame(Varien_Object $object, $level = 1) { $frame = new Varien_Object(); $frame->setFrameId('category' . $object->getId()); $frame->setFrameCategoryId($object->getId()); $frame->setHeader($object->getName()); $frame->setLevel($level + 1); if (Mage::getStoreConfig('catalog/frontend/flat_catalog_category')) { $frame->setChildren($object->getChildrenNodes()); } else { $frame->setChildren($object->getChildren()); } $frame->setChildrenCount($this->__getChildrenCount($object)); if (Mage::getStoreConfig('catalog/frontend/flat_catalog_category')) { if (is_array($frame->getChildrenNodes()) || is_object($frame->getChildrenNodes()) && get_class($frame->getChildrenNodes()) == 'Varien_Data_Tree_Node_Collection') { foreach ($frame->getChildrenNodes() as $child) { $this->_frames[] = $this->_getFrame($child, $level + 1); } } } else { if (is_array($frame->getChildren()) || is_object($frame->getChildren()) && get_class($frame->getChildren()) == 'Varien_Data_Tree_Node_Collection') { foreach ($frame->getChildren() as $child) { $this->_frames[] = $this->_getFrame($child, $level + 1); } } } return $frame; }
/** * calculate earning for quote/order item * * @param Varien_Object $item * @param int $customerGroupId * @param int $websiteId * @param string $date * @return int */ public function getCatalogItemEarningPoints($item, $customerGroupId = null, $websiteId = null, $date = null) { $product = Mage::getModel('catalog/product')->load($item->getProductId()); //webpos $customerId = Mage::getSingleton('checkout/session')->getData('webpos_customerid'); if ($customerId) { $customerGroupId = Mage::getModel('customer/customer')->load($customerId)->getGroupId(); } else { $customerGroupId = Mage_Customer_Model_Group::NOT_LOGGED_IN_ID; } if (is_null($websiteId)) { $websiteId = Mage::app()->getStore($item->getStoreId())->getWebsiteId(); } if (is_null($date)) { $date = date('Y-m-d', strtotime($item->getCreatedAt())); } $cacheKey = "catalog_item_earning:{$item->getId()}:{$customerGroupId}:{$websiteId}"; if ($this->hasCache($cacheKey)) { return $this->getCache($cacheKey); } $points = 0; $collectionKey = "catalog_earning_collection:{$customerGroupId}:{$websiteId}"; if (!$this->hasCache($collectionKey)) { $rules = Mage::getResourceModel('rewardpointsrule/earning_catalog_collection')->setAvailableFilter($customerGroupId, $websiteId, $date); foreach ($rules as $rule) { $rule->afterLoad(); } $this->saveCache($collectionKey, $rules); } else { $rules = $this->getCache($collectionKey); } if ($item->getHasChildren() && $item->isChildrenCalculated()) { $price = 0; $profit = 0; foreach ($item->getChildren() as $child) { $price += $child->getQty() * $child->getBasePrice(); $profit += $child->getQty() * ($child->getBasePrice() - $child->getBaseCost()); } } else { $price = $item->getBasePrice(); if (!$price && $item->getPrice()) { $price = $item->getPrice() / Mage::app()->getStore($item->getStoreId())->convertPrice(1); } $profit = $price - $item->getBaseCost(); } foreach ($rules as $rule) { if ($rule->validate($product)) { $points += $this->calcCatalogPoint($rule->getSimpleAction(), $rule->getPointsEarned(), $price, $profit, $rule->getMoneyStep(), $rule->getMaxPointsEarned()); if ($rule->getStopRulesProcessing()) { break; } } } $this->saveCache($cacheKey, $points * $item->getQty()); return $this->getCache($cacheKey); }