Online mall promotion Design

Source: Internet
Author: User

The previous article is about the design of the shopping cart, which is about promotion.

The supported promotions are similar to discounts, how many gifts to buy, and how much money to give gifts. The policy mode is used.

 

The general idea is that a promotion class should be created for each promotion, and a special switch is provided to control whether the promotion is effective.

Use the sales identification code in the product to determine which sales promotion instance to call.

 

First, you can add a product in two steps. The first step is to add the product status. The second step is to display the product status in the shopping cart.

1. Add steps:

1. traverse all promotion mutex conditions before adding products.

For example, a product cannot be in the same shopping cart with another product; or a user can not buy a specific product.

2. Select a specific promotion instance before adding the product.

Note: The difference between the second and the first is that 1 is to traverse all promotion instances, and 2 is a separate one.

3. After adding a product, perform the operations based on the specific promotion instance.

1 /**
2 * Add a product to the shopping cart
3 * @ Param int $ goods_id product ID
4 * @ Param string $ goods_spec product specifications
5 * @ Param int $ goods_number product quantity
6 * @ Param string $ promote_name participate in the activity
7 * @ return bool
8 */
9 Public Function goodsadd ($ goods_id, $ goods_spec, $ goods_number, $ promote_name)
10 {
11 // obtain all valid promotion instances
12 $ rules = $ this-> _ getallruleinstance ();
13 foreach ($ this-> _ rules as $ instance)
14 {
15 // mutual exclusion judgment
16 if (! $ Instance-> goodsexclusion ($ goods_id, $ goods_spec ))
17 {
18 return false;
19}
20}
21 // obtain a separate promotion instance for the product
22 $ rule = $ this-> _ getruleinstance ($ promote_name );
23 // before adding a product
24 if ($ rule-> beforegoodsadd ())
25 {
26 $ rule-> goodsadd ($ goods_id, $ goods_spec, $ goods_number );
27 // after adding a product
28 return $ rule-> aftergoodsadd ();
29}
30 return false;
31}

 

1 /**
2 * get the list of available rule instances
3 * @ return Array
4 */
5 private function _ getallruleinstance ()
6 {
7 if (empty ($ this-> _ Rules ))
8 {
9 $ dir = dirname (_ file _). '/cart/Rule /';
10 $ dir_handle = opendir ($ DIR );
11 while ($ file = readdir ($ dir_handle ))
12 {
13 if (is_file ($ dir. $ file ))
14 {
15 $ instance = $ this-> _ getruleinstance (substr ($ file, 0, strpos ($ file ,'.')));
16 if ($ instance-> enabled ())
17 {
18 $ this-> _ rules [] = $ instance;
19}
20}
21}
22}
23 return $ this-> _ rules;
24}
/**
* Getting shopping cart rules
* @ 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 purpose of the promotion here is to determine whether a person has the permission to add the product, such as discounts.

2. Traverse shopping cart operations

In this step, the key operation is to traverse all the inspection list functions of the promotion policy.

Here, we often use promotions such as full money, gifts, buy two get one free, and so on.

1 /**
2 * get the list of items in the shopping cart.
3 * @ return array Bll_Shop_Cart_Rule
4 */
5 public function goodsViewList ()
6 {
7 $ list = $ this-> getGoodsList ();
8
9 // check the item list in the shopping cart when listing
10 $ rules = $ this-> _ getAllRuleInstance ();
11 foreach ($ this-> _ rules as $ instance)
12 {
13 $ instance-> setGoodsList ($ list)-> goodsCheckList ();
14 $ this-> _ tip_rules [] = $ instance;
15}
16
17 // get the latest shopping cart list
18 $ goods_list = $ this-> _ cart-> getGoodsList ();
19 return $ goods_list;
20}

Third, the operations before submitting the order

There are some types of promotions. For example, if someone has the discount permission, after the order is placed, the discount permission is used up. Or, before placing an order, check the order amount, if the number is less than the number, you are not allowed to place this order.

All of the above operations will be performed 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.