PHP Online Mall Promotion Design example code _php tutorial

Source: Internet
Author: User
Tags php online
General idea, every promotion to create a new promotion class, there is a special switch to control whether or not to take effect.
Use the promotional identification code in the product to determine which promotion instance to call.
First of all, when adding a product, in two steps, the first step is to add the state, the second step is to show the item in the shopping cart this state.
One, add several important points to the steps:
1, before adding a product, traverse all promotion mutex conditions.
For example, a product cannot be in a shopping cart with another item at the same time, or a certain user right can not buy a particular item, and so on.
2. Before adding a product, select a specific promotion instance to add the previous action.
Note: The difference between the 2nd and the 1th is that 1 is to traverse all promotional instances, while 2 is a separate article.
3, after adding the item, according to the specific promotion instance, the action to be done.
Copy CodeThe code is as follows:
/**
* Add items to your shopping cart
* @param int $goods _id Product ID
* @param string $goods _spec product Specifications
* @param int $goods _number Item Quantity
* @param string $promote _name Merchandise participation Activity
* @return BOOL
*/
Public Function Goodsadd ($goods _id, $goods _spec, $goods _number, $promote _name)
{
Get all valid promotional instances
$rules = $this->_getallruleinstance ();
foreach ($this->_rules as $instance)
{
The mutual judgment of exchanging gifts
if (! $instance->goodsexclusion ($goods _id, $goods _spec))
{
return false;
}
}
Get an individual promotion instance of a product
$rule = $this->_getruleinstance ($promote _name);
Action before adding an item
if ($rule->beforegoodsadd ())
{
$rule->goodsadd ($goods _id, $goods _spec, $goods _number);
Actions after adding a product
return $rule->aftergoodsadd ();
}
return false;
}

Copy CodeThe code is 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 CodeThe code is as follows:
/**
* Get Shopping cart rules 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 rules object loading exception. Rule_name: '. $rule _name);
throw new Exception (' Shopping rules object loading exception. ');
}
}

Here the main use of the promotion is to determine whether a person has the right to add this product, discounts and so on.
Second, the operation of traversing shopping cart goods
The key operation for this step is to traverse the check list function of all promotional policies.
Here can often use the promotion is full of money, send gifts, buy two get one and so on.
Copy CodeThe code is as follows:
/**
* Get list of items in 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 action before the order is submitted
There are some types of promotions, such as someone has the right to discount, after the order is finished, the privilege of the discount is used, or before the order is placed to check the amount of the orders, if less than the number is not allowed to place the order and so on.
All of this will be done before the order is submitted.

http://www.bkjia.com/PHPjc/324963.html www.bkjia.com true http://www.bkjia.com/PHPjc/324963.html techarticle General idea, every promotion to create a new promotion class, there is a special switch to control whether or not to take effect. Use the promotional identification code in the product to determine which promotion instance to call. ...

  • Related Article

    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.