(Free) Gift Wrapping Service – Magento EE

gift_featured © Stock Photo

Maybe you’ve wondered how not to charge for the Gift Wrapping Services for customers that have more items in their cart. We’ve gotten a request where client wanted to provide free Gift Wrapping Services (Gift Card, Gift Wrap, Gift Message) for their customers with total basket value above a certain limit. If you are wondering how we did it, keep reading.

Shortly about Gift Wrapping module, from Magento Enterprise Edition User Guide:
“In Magento Enterprise Edition, store customers can select a gift message and/or gift wrapping for the entire order, as well as for separate order items, and a printed card, such as a picture post card, to the order. You can process the gift wrapping and printed card, and charge customers for them, as well as add gift messages, gift wrapping, and a gift card in orders that are created from the Admin Panel.
This feature was introduced in Version 1.10 of Magento Enterprise Edition.”

Basically we’ll need to rewrite one model and we’ll need to create our helper class which will check for us can we show Free Gift Wrapping Service – only if value of items in basket is above certain limit.

  1. Tell Magento about our module
  2. Create configuration file
  3. Create system.xml file
  4. Rewrite Required Model
  5. Create Our Helper class
  6. Tweak frontend look and feel

So let’s start.

1. Tell Magento about our module

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>

2. Create configuration file

Create 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>

3. Create system.xml file

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“.

4. 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;
    }
 
}

5. Create Helper class

Create 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;
 
    }
}

And for the end we can tweak desired frontend look and feel ­čÖé

6. Front-end modifications

For example you can open file: app/design/frontend/enterprise/[YOUR_THEME]/template/giftwrapping/checkout/options.phtml and 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.

And as the end result you might come up with something similar to the next screenshoot:

Gift Wrapping Example

Note that for production ready code you’ll need first to check and decide which amount should be default for your base currency, otherwise system might show free of charge Gift Wrapping Service.

Did you have any similar request? How have you handled it?

In one of my next posts I’ll show you how you can enable Gift Wrapping module only for customers from certain countries, so stay tuned!


2 comments

  1. I cant understand your last step means 6th step. Please give me brief information for that. If you give me the details info then I can develop this module.

  2. Hi,

    I am stuck in last 6th step , what to do there, please explain a bit more so I can carry on this module development.

    Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.