復制代碼 代碼如下:
/**
* 向購物車內添加商品
* @param int $goods_id 商品ID
* @param string $goods_spec 商品規格
* @param int $goods_number 商品數量
* @param string $promote_name 商品參加活動
* @return bool
*/
public function goodsAdd($goods_id, $goods_spec, $goods_number, $promote_name)
{
//獲取所有有效的促銷實例
$rules = $this->_getAllRuleInstance();
foreach($this->_rules as $instance)
{
//換禮互斥判斷
if(!$instance->goodsExclusion($goods_id, $goods_spec))
{
return false;
}
}
//獲取商品單獨的促銷實例
$rule = $this->_getRuleInstance($promote_name);
//添加商品之前操作
if($rule->beforeGoodsAdd())
{
$rule->goodsAdd($goods_id, $goods_spec, $goods_number);
//添加商品之后操作
return $rule->afterGoodsAdd();
}
return false;
}
復制代碼 代碼如下:
/**
* 獲取可用規則實例列表
* @return array
*/
private function _getAllRuleInstance()
{
if(empty($this->_rules))
{
$dir = dirname(__FILE__).'/Cart/Rule/';
$dir_handle = opendir($dir);
while($file = readdir($dir_handle))
{
if(is_file($dir.$file))
{
$instance = $this->_getRuleInstance(substr($file, 0, strpos($file, '.')));
if($instance->enabled())
{
$this->_rules[] = $instance;
}
}
}
}
return $this->_rules;
}
復制代碼 代碼如下:
/**
* 獲取購物車規則類
* @param string $name 規則名稱
* @return Bll_Shop_Cart_Rule
*/
private function _getRuleInstance($name)
{
$rule_name = 'Bll_Shop_Cart_Rule_'.$name;
try
{
Zend_Loader::loadClass($rule_name);
$this->_rule = new $rule_name();
$this->_rule->setCart($this);
return $this->_rule;
}catch (Exception $e)
{
Bll_LogWriter::logException('購物規則對象加載異常. rule_name:'.$rule_name);
throw new Exception('購物規則對象加載異常.');
}
}
復制代碼 代碼如下:
/**
* 獲取購物車內商品清單對象列表
* @return array Bll_Shop_Cart_Rule
*/
public function goodsViewList()
{
$list = $this->getGoodsList();
// 在列表時檢查購物車內商品列表
$rules = $this->_getAllRuleInstance();
foreach($this->_rules as $instance)
{
$instance->setGoodsList($list)->goodsCheckList();
$this->_tip_rules[] = $instance;
}
//獲取最新購物車列表
$goods_list = $this->_cart->getGoodsList();
return $goods_list;
}
新聞熱點
疑難解答