如果用户在magento上购买特价商品,则限制他们参加竞争


Restrict users to join competition if they buy products that are on special on 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;
        }
    }

/******************em>**********/

相关文章: