如果用户购买正在销售的产品,则限制用户加入竞争
我想创造一个条件,如果客户购买特价产品,他会收到一条消息说你有 10% 的折扣,否则如果客户购买非特价产品,他会收到一条消息说谢谢与我们一起购买。
我检查了magento论坛,但没有运气。
如果用户购买正在销售的产品,则限制用户加入竞争
我想创造一个条件,如果客户购买特价产品,他会收到一条消息说你有 10% 的折扣,否则如果客户购买非特价产品,他会收到一条消息说谢谢与我们一起购买。
我检查了magento论坛,但没有运气。
/*********************************************************************************************/
//how many vouchers the user wants to add
$voucher_products = 0;
//how many products vouchers can be used on
$vouchers_added = 0;
//grabbing the quote object from session
$quote = Mage::getSingleton('checkout/session')->getQuote();
//fetching all cart items from the quote
$items = $quote->getAllVisibleItems('name');
//We need to load the category for infantmilks
$category = Mage::getModel('catalog/category')->loadByAttribute('name', 'Infant Milks');
/* We need to perform a check to ensure that this category exists, by name. if it is not found using
* the name, the feature will not work. return an error message.
*/
if(!$category)
{
$this->addErrorMessage('There is an issue with the Voucher System. Please contact the site administrator.');
return;
}
//grab the production collection
$products_list = $category->getProductCollection();
/* Loop over all cart items, checking how many are
* part of the infantsmilk category. if an item is found
* that is part of the category, increment voucher_products.
*/
foreach ($items as $item) {
foreach ($products_list as $product){
if($item['product_id'] === $product->getId()){
$voucher_products = $voucher_products + 1;
}
}
}
//load the entires from the healthy start entity
$vouchers = Mage::getResourceModel('healthystart/voucher_collection');
//loop over all vouchers and checks if there are any vouchers in the current quote
foreach($vouchers as $voucher){
if ($voucher['quote_id'] === $item['quote_id']){
$vouchers_added = $vouchers_added + 1;
}
}
if ($voucher_products === 0){
$this->addErrorMessage('Healthy Start Vouchers can only be used on Infant Milks.
Please add an Infant Milks product to your basket to redeem your voucher.');
return;
}
else {
if($vouchers_added >= $voucher_products){
$this->addErrorMessage('You can not add another voucher.');
return;
}
}
/ * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * * /