php 网上商城促销设计实例代码_PHP
大体的思想,每一个促销要新建一个促销类,有专门的开关来控制是否生效。
用商品里面的促销识别码来判断具体调用哪一个促销实例。
首先,在添加商品的时候,分两步,第一步是添加状态,第二步是把购物车内的商品显示这个状态。
一,添加步骤几个重要的点:
1,添加商品之前,遍历所有的促销互斥条件。
例如,某一款商品不可以和另一个商品同时在一个购物车内;或者某个用户权限,不可以购买特定的一件商品等等。
2,添加商品之前,选择特定的促销实例,来进行添加之前的操作。
注:第二点与第一点的区别在于1是要遍历所有的促销实例,而2是单独的一条。
3,添加商品后,根据特定的促销实例,所要进行的操作。
复制代码 代码如下:
/**
* 向购物车内添加商品
* @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;
}
第三,提交订单之前的操作
有一些类型的促销,比如某人有打折的权限,当下完订单后,这个打折的权限就被用掉了;或者在下单之前要先检查这个订单的金额,如果小于多少就不准下这个订单等等。
以上这些都会用到提交订单之前的操作。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Key points of price strategy and promotion design in PHP flash sale system In a flash sale system, price strategy and promotion design are very important parts. Reasonable price strategies and well-designed promotions can attract users to participate in flash sale activities and improve the user experience and profitability of the system. The following will introduce the key points of price strategy and promotional activity design in the PHP flash sale system in detail, and provide specific code examples. 1. Key points in price strategy design: Determine the benchmark price: In the flash sale system, the benchmark price refers to the price of the product when it is normally sold. exist

How to write a simple online mall system using C++? With the development of the Internet, e-commerce has become one of the main ways for people to shop. In order to meet users' shopping needs, it is very necessary to develop a simple and practical online mall system. This article will introduce how to use C++ to write a simple online mall system. 1. Requirements analysis Before starting to write the online mall system, you first need to conduct a needs analysis. According to the functional characteristics of the online mall, we can determine the following requirements: User registration and login: Users can register

How to implement the product original price promotion function in PHP Developer City With the development and popularity of e-commerce, more and more merchants choose to open their own shopping malls online. In shopping malls, promotional activities are one of the important means to attract consumers, and original price promotion of goods is a common and effective marketing method. This article will introduce how to implement the original price promotion function of goods in a mall developed in PHP. 1. Database design Before realizing the function of product original price promotion, database design first needs to be carried out. Create a product table containing product ID and product name

References include: 1. "PHP and MySQL Web Development"; 2. "PHP Advanced Programming"; 3. "PHP Objects, Patterns, and Practice"; 4. "Laravel: Up and Running"; 5. "E-commerce" in PHP"; 6. PHP official documentation; 7. Laravel official documentation; 8. PHP website development tutorial; 9. Laravel tutorial; 10. GitHub, etc.

Best Practices for Building an Online Mall with PHP and Typecho With the rapid development of e-commerce, more and more people are turning to online shopping. In order to meet this demand, many developers began to explore how to use PHP and Typecho to build a complete online mall. This article will introduce the best practices for using PHP and Typecho to build an online mall and provide some code examples. Typecho is a simple and efficient PHP blog system with a flexible plug-in system and user-friendly backend management.

According to news from this website on November 28, the Taobao Merchant Service Hall showed that this year’s Double 12 event has been cancelled, and has been changed to the “Taobao Year-end Good Price Festival”, which will start at 8 pm on December 9. Investment is now open, and event products are not required. Provide price protection services. This event has two types of gameplay: "cross-store full discount" and "official instant discount", with a discount of 30 yuan for every purchase of 200 yuan or more. Cross-store full discounts support combined payment for cross-store types of products, that is, Taobao products and Tmall products that meet the conditions for cross-store full discounts can be combined for payment and use the discount. Registration time Seller registration: November 27, 2023 12:00:00-December 12, 2023 23:59:59 Product registration time is November 27, 2023 12:00:00 to 2023

According to news on August 18, it was recently reported that NIO, a well-known Chinese electric vehicle manufacturer, has launched a limited-time preferential policy in order to promote its inventory models. It is understood that this promotion is targeted at Weilai's ET5 model. For specific batches of vehicles that have been in stock for more than 90 days, car buyers can enjoy a direct cash discount of up to 24,000 yuan. This promotion started last week and is expected to last until the end of next week. According to reports, the average inventory time of the ET5 stock models participating in this promotion exceeds 100 days, and even a few exhibition cars have an inventory time of more than 200 days. NIO sales staff revealed that this preferential policy is specially designed for ET5 models that have been in stock for more than 90 days. Consumers place orders to purchase ET on NIO’s official app

In the current era of rapid development of e-commerce, promotional activities have become one of the important means for malls to attract customers and increase sales. With the continuous advancement of technology, many shopping malls have begun to use the promotion function developed by PHP. This article will evaluate the effectiveness of mall promotions developed using PHP from different perspectives. First, we need to understand what PHP is. PHP is a very popular server-side scripting language that is widely used in web development. Compared with other languages, PHP is easy to learn and use, highly open, and has good compatibility.
