0

I want to override wishlist block in my custom theme. Whenever Customer increases the QTY on wishlist page for add to cart, I want to place the condition that QTY should be less than 5.

This function is already written in /Mage/Wishlist/Block/Customer/Wishlist/Item/Column/Cart.php.

I want to override this in my custom theme.

app/code/local/Gt/Wishlist/Block/Customer/Wishlist/Item/Column/Cart.php

class Gt_Wishlist_Block_Customer_Wishlist_Item_Column_Cart extends 

Mage_Wishlist_Block_Customer_Wishlist_Item_Column
{
    /**
     * Returns qty to show visually to user
     *
     * @param Mage_Wishlist_Model_Item $item
     * @return float
     */
    public function getAddToCartQty(Mage_Wishlist_Model_Item $item)
    {
        $qty = $item->getQty();
        return $qty ? $qty : 1;
    }

    /**
     * Retrieve column related javascript code
     *
     * @return string
     */
    public function getJs()
    {
        $js = "
            function addWItemToCart(itemId) {
                var url = '" . $this->getItemAddToCartUrl('%item%') . "';
                url = url.gsub('%item%', itemId);
                var form = $('wishlist-view-form');
                if (form) {
                    var input = form['qty[' + itemId + ']'];
                    if (input) {
                        var separator = (url.indexOf('?') >= 0) ? '&' : '?';
                        url += separator + input.name + '=' + encodeURIComponent(input.value);
                        if(input.value > 5){
                            alert('Select between 1 to 5');
                            return false;
                        }
                    }
                }
                setLocation(url);
            }
        ";

        $js .= parent::getJs();
        return $js;
    }
}

app/code/local/Gt/Wishlist/etc/config.xml

<?xml version="1.6.0.0"?>
<config>
  <modules>
    <Gt_Wishlist>
      <version>1.0</version>
    </Gt_Wishlist>
  </modules>
    <resources>
        <Gt_Wishlist_setup>
            <setup>
                <module>Gt_Wishlist</module>
            </setup>
        </Gt_Wishlist_setup>
    </resources>
  <global>
    <blocks>
      <wishlist>
        <rewrite>
          <column_cart>Gt_Wishlist_Block_Customer_Wishlist_Item_Column_Cart</column_cart>
        </rewrite>
    </wishlist>
    </blocks>
  </global>
</config>

These two files i have overriden in my custom theme as i shared folder path. Please help me.

0

You have to rewrite Mage/Wishlist/Block/Customer/Wishlist/Item/Column/Cart.php in local codepool instead of theme.

app/code/... will be rewrited in local codePool.

app/design/... will be overrited in current theme.

Now according to this rules, your block will be rewrited of course in local.

You have good This Inchoo explanation for rewriting blocks, helpers, controllers, etc...

| improve this answer | |
  • I have read that blog, but I am not getting properly. I i want to only override that cart.php, is it compulsory to override other folders such etc, controllers, models, sql ?? Please help me. – gt06 Oct 16 '17 at 13:42
  • No, you have just rewrite this block, and not necessarily the others controllers, models ... – PЯINCƏ Oct 16 '17 at 13:47
  • so what will be the next step to override this cart.php. I have done this 3 times. but not overriding that block. – gt06 Oct 17 '17 at 4:01

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.