复制代码 代码如下:
/**
* 向购物车内添加商品
* @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;
}
新闻热点
疑难解答