PHP Online Mall Promotion Design instance code _php instance

Source: Internet
Author: User
Tags php online
General thinking, each promotion to create a new promotional category, there are special switches to control whether it takes effect.
Use the promotional identification code inside the product to determine which promotional instance to call specifically.
First of all, in the addition of goods, in two steps, the first step is to add the state, the second step is the shopping cart to show this state of goods.
One, add several important points to the steps:
1, before adding a product, traverse all promotional mutex conditions.
For example, a product cannot be in a shopping cart at the same time as another item, or a user right, and you cannot buy a particular item, and so on.
2, before adding a product, select a specific promotional instance to do before adding the action.
Note: The difference between 2nd and 1th is that 1 is going to traverse all promotional instances, and 2 is a separate one.
3, after adding the product, according to the specific promotional examples, the operation to be done.
Copy Code code as follows:

/**
* Add merchandise to Shopping cart
* @param int $goods _id Product ID
* @param string $goods _spec Commodity Specifications
* @param int $goods _number Commodity Quantity
* @param string $promote _name commodity participation activities
* @return BOOL
*/
Public Function Goodsadd ($goods _id, $goods _spec, $goods _number, $promote _name)
{
Get all the effective promotional examples
$rules = $this->_getallruleinstance ();
foreach ($this->_rules as $instance)
{
The mutual exclusion judgment of exchanging gifts
if (! $instance->goodsexclusion ($goods _id, $goods _spec))
{
return false;
}
}
Get a separate promotional example for a commodity
$rule = $this->_getruleinstance ($promote _name);
Action before adding a product
if ($rule->beforegoodsadd ())
{
$rule->goodsadd ($goods _id, $goods _spec, $goods _number);
Action after adding merchandise
return $rule->aftergoodsadd ();
}
return false;
}

Copy Code code as follows:

/**
* Get a list of available rule instances
* @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;
}

Copy Code code as follows:

/**
* Get the shopping cart rule class
* @param string $name rule 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 (' Shopping rule object loading exception. Rule_name: '. $rule _name);
throw new Exception (' Shopping rule object loading exception. ');
}
}

The main use of the promotion here is to determine whether a person has to add the right to the goods, discounts and so on.
Second, to traverse the operation of shopping cart merchandise
The key operation in this step is to traverse the check list function of all promotional policies.
This is often used in the promotion is how much money, send gifts, buy two to send a and so on.
Copy Code code as follows:

/**
* Get a list of the merchandise list objects in the shopping cart
* @return Array Bll_shop_cart_rule
*/
Public Function Goodsviewlist ()
{
$list = $this->getgoodslist ();
Check the list of items in your shopping cart when you list
$rules = $this->_getallruleinstance ();
foreach ($this->_rules as $instance)
{
$instance->setgoodslist ($list)->goodschecklist ();
$this->_tip_rules[] = $instance;
}
Get the latest shopping cart list
$goods _list = $this->_cart->getgoodslist ();
return $goods _list;
}

Third, the operation before the order is submitted
There are some types of promotions, such as someone with the right to discount, after the current order, the discount permission is used, or before the order to check the amount of the orders, if less than the number of the order, and so on.
All of the above will be used before the order is submitted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.