00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 class Mage_SalesRule_Model_Rule_Condition_Product_Found
00029 extends Mage_SalesRule_Model_Rule_Condition_Product_Combine
00030 {
00031 public function __construct()
00032 {
00033 parent::__construct();
00034 $this->setType('salesrule/rule_condition_product_found');
00035 }
00036
00037 public function loadValueOptions()
00038 {
00039 $this->setValueOption(array(
00040 1=>'FOUND',
00041 0=>'NOT FOUND',
00042 ));
00043 return $this;
00044 }
00045
00046 public function asHtml()
00047 {
00048 $html = $this->getTypeElement()->getHtml().
00049 Mage::helper('salesrule')->__("If an item is %s in the cart with %s of these conditions true:",
00050 $this->getValueElement()->getHtml(), $this->getAggregatorElement()->getHtml());
00051 if ($this->getId()!='1') {
00052 $html.= $this->getRemoveLinkHtml();
00053 }
00054 return $html;
00055 }
00056
00057
00058
00059
00060
00061
00062
00063 public function validate(Varien_Object $object)
00064 {
00065 $all = $this->getAggregator()==='all';
00066 $true = (bool)$this->getValue();
00067 $found = false;
00068 foreach ($object->getAllItems() as $item) {
00069 $found = $all ? true : false;
00070 foreach ($this->getConditions() as $cond) {
00071 $validated = $cond->validate($item);
00072 if ($all && !$validated) {
00073 $found = false;
00074 break;
00075 } elseif (!$all && $validated) {
00076 $found = true;
00077 break 2;
00078 }
00079 }
00080 if ($found && $true) {
00081 break;
00082 }
00083 }
00084 if ($found && $true) {
00085
00086
00087 return true;
00088 } elseif (!$found && !$true) {
00089
00090 return true;
00091 }
00092 return false;
00093 }
00094 }