1

I want to set the price for particular gift option like the gift-card message on checkout page..how to do it please provide the proper way to set the price for gift-message

0

Example code of adding Gift Wrapping price

Create file app/etc/modules/Inchoo_GiftWrapping.xml with the following content:

<config>
    <modules>
        <Inchoo_GiftWrapping>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Enterprise_GiftWrapping/>
            </depends>
        </Inchoo_GiftWrapping>
    </modules>
</config>

Create configuration file app/code/local/Inchoo/GiftWrapping/etc/config.xml with the following content:

<?xml version="1.0"?>
<config>
    <modules>
        <Inchoo_GiftWrapping>
            <version>1.0.0.0</version>
        </Inchoo_GiftWrapping>
    </modules>
    <global>
        <models>
            <enterprise_giftwrapping>
                <rewrite>
                    <total_quote_giftwrapping>Inchoo_GiftWrapping_Model_Total_Quote_Giftwrapping</total_quote_giftwrapping>
                </rewrite>
            </enterprise_giftwrapping>
        </models>
        <helpers>
            <inchoo_giftwrapping>
                <class>Inchoo_GiftWrapping_Helper</class>
            </inchoo_giftwrapping>
        </helpers>
    </global>
 </config>

Important and useful step

Create file app/code/local/Inchoo/GiftWrapping/etc/system.xml with the following content:

<config>
    <sections>
        <sales>
            <groups>
                <gift_options>
                    <fields>
                        <free_gift_wrapping_price translate="label" module="inchoo_giftwrapping">
                            <label>Charge for Gift Wrap Service if the basket value is under</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>15</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>0</show_in_website>
                            <show_in_store>0</show_in_store>
                            <can_be_empty>1</can_be_empty>
                        </free_gift_wrapping_price>
                    </fields>
                </gift_options>
            </groups>
        </sales>
    </sections>
</config>

Note that now you can see in Magento administration under System/Configuration/Sales/Sales/Gift Options tab new input field where you can specify desired amount for: “Charge for Gift Wrap Service if the basket value is under“.

Rewrite Model Create file app/code/local/Inchoo/GiftWrapping/Model/Total/Quote/Giftwrapping.php with the following content:

<?php

/**
 * GiftWrapping total calculator for quote
 * @category    Inchoo
 * @package     Inchoo_GiftWrapping
 * @author      Ivan Galambos <ivan.galambos@inchoo.net>
 */
class Inchoo_GiftWrapping_Model_Total_Quote_Giftwrapping extends Enterprise_GiftWrapping_Model_Total_Quote_Giftwrapping
{
    /**
     * Collect wrapping total for quote
     *
     * @param   Mage_Sales_Model_Quote_Address $address
     * @return  Enterprise_GiftWrapping_Model_Total_Quote_Giftwrapping
     */
    protected function _collectWrappingForQuote($address)
    {
        $wrappingBasePrice = false;
        $wrappingPrice = false;

        //include price if !canuseFreeGiftWrapping
        if ( !(Mage::helper('inchoo_giftwrapping')->canUseFreeGiftWrapping()) ) {
            if ($this->_quoteEntity->getGwId()) {
                $wrapping = $this->_getWrapping($this->_quoteEntity->getGwId(), $this->_store);
                $wrappingBasePrice = $wrapping->getBasePrice();
                $wrappingPrice = $this->_store->convertPrice($wrappingBasePrice);
            }
        }

        $address->setGwBasePrice($wrappingBasePrice);
        $address->setGwPrice($wrappingPrice);
        return $this;
    }

    /**
     * Collect printed card total for quote
     *
     * @param   Mage_Sales_Model_Quote_Address $address
     * @return  Inchoo_GiftWrapping_Model_Total_Quote_Giftwrapping
     */
    protected function _collectPrintedCard($address)
    {
        $printedCardBasePrice = false;
        $printedCardPrice = false;

        //include price if !canuseFreeGiftWrapping
        if ( !(Mage::helper('inchoo_giftwrapping')->canUseFreeGiftWrapping()) ) {
            if ($this->_quoteEntity->getGwAddCard()) {
                $printedCardBasePrice = Mage::helper('enterprise_giftwrapping')->getPrintedCardPrice($this->_store);
                $printedCardPrice = $this->_store->convertPrice($printedCardBasePrice);
            }
        }

        $address->setGwCardBasePrice($printedCardBasePrice);
        $address->setGwCardPrice($printedCardPrice);
        return $this;
    }

}

Create Helper Class file app/code/local/Inchoo/GiftWrapping/Helper/Data.php with the following content:

<?php

/**
 * GiftWrapping helper data
 *
 * @category    Inchoo
 * @package     Inchoo_GiftWrapping
 * @author      Ivan Galamboš <ivan.galambos@inchoo.net>
 */
class Inchoo_GiftWrapping_Helper_Data extends Mage_Core_Helper_Abstract
{
    /**
     * Min. base price to get free GiftWrapping Service
     *
     * @var mixed
     */
    public $_baseFreePrice = null;

    /**
     * can use free Gift Wrapping service
     *
     * @var mixed
     */
    public $freeGiftWrapping = null;

    /**
     * Return limit as base price for free Gift Wrapping Service
     *
     * @return flaot
     */
    public function getBasePriceForFreeGiftWrappingService()
    {
        if (empty($this->_baseFreePrice)) {
            $this->_baseFreePrice = (float)Mage::getStoreConfig('sales/gift_options/free_gift_wrapping_price');
        }

        return $this->_baseFreePrice;
    }

    /**
     * Can show free Gift Wrapping Service on frontend
     * Basket value must be grater or equal to set price for Free Gift Wrapping Service
     *
     * @return bool
     */
    public function canUseFreeGiftWrapping()
    {
        if (!is_bool($this->freeGiftWrapping)) {

            $baseFreeGift = $this->getBasePriceForFreeGiftWrappingService();
            $baseTotal = Mage::getModel('checkout/session')->getQuote()->getBaseGrandTotal();

            if ( $baseTotal >= $baseFreeGift ) {
                $this->freeGiftWrapping = true;
            } else {
                $this->freeGiftWrapping = false;
            }

        }

        return $this->freeGiftWrapping;

    }
}

Front-end modifications For example you can open file: app/design/frontend/enterprise/[YOUR_THEME]/template/giftwrapping/checkout/options.phtmland add 2 modifications (you don’t want to change core file – if you don’t have one please copy one):

1) in gift-wrapping-container area you can replace with:

<span class="regular-price">
                        <span class="label"><?php echo $this->__('Price') ?>:</span>
                        <?php if (Mage::helper('inchoo_giftwrapping')->canUseFreeGiftWrapping()):?>
                            <span class="price"><?php echo $this->__('Free') ?></span>
                        <?php else: ?>
                            <span class="price" id="regular-price-{{id}}"></span>
                        <?php endif; ?>
</span>

and 2) in gift-options-container area you can replace with:

<span class="regular-price">
                    <span class="label"><?php echo $this->__('Price') ?>:</span>
                    <span class="price" id="regular-card-price-{{id}}">
                    <?php echo (Mage::helper('inchoo_giftwrapping')->canUseFreeGiftWrapping()) ? $this->__('Free') : '{{price}}'; ?></span>
</span>

Now your customers will see “Free” price instead of regular one on checkout page for Gift Wrapping service & Printed Card feature.

I hope this will help

  • after installing this module it shows me an error "Module "Inchoo_GiftWrapping" requires module "Enterprise_GiftWrapping"." – Naresh Prajapati Apr 12 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.