Question

Magento shopping cart is built on the Zend Framework in PHP. This is the first time I've dealt with the Zend framework and I'm having the following difficulty...

I'm creating a custom module that will allow users to upload images whenever they purchase products.

I can overload the addAction() method whenever a user attempts to add a product to their cart. I can also create a custom module which presents the form to the user and accepts the file(s). However I'm not sure how to insert the code to run my module into my overloaded method:

<?php
require_once 'Mage/Checkout/controllers/CartController.php';
class Company_SpecialCheckout_Checkout_CartController extends Mage_Checkout_CartController
{
    # Overloaded addAction
    public function addAction()
    {
        # when user tries to add to cart, request images from them
        # *********
        # *** what do i do in here to display a custom block ???? ###
        # *** and allow addAction to continue only if successfully validated form input ###
        # *********

        parent::addAction();
    }
} 

I suspect my difficulties come from my lack of knowledge of the Zend MVC way of doing things. I've studied all the Magento documentation/wikis/forum threads from top to bottom.

Was it helpful?

Solution

hey this option is given in newer version of magento 1.3.1 to upload the file from frontend enjoy

OTHER TIPS

I thought I'd move to a new answer as I think I've managed to get it working.

Here's what I did

created the following files;

app/code/local/Company/SpecialCheckout/controllers/Checkout/CartController.php

app/code/local/Company/SpecialCheckout/etc/config.xml

app/etc/modules/Company_SpecialCheckout.xml

First the controller, which is exactly as you had;

    <?PHP
require_once 'Mage/Checkout/controllers/CartController.php';
class Company_SpecialCheckout_Checkout_CartController extends Mage_Checkout_CartController {

    public function indexAction()
    {
        die('test');
    }
}

Then the module configuration

<?xml version="1.0"?>
<config>
    <modules>
        <Company_SpecialCheckout>
            <version>0.1.0</version>
        </Company_SpecialCheckout>
    </modules>
    <global>
        <rewrite>
            <Company_SpecialCheckout_Checkout_Cart>
                <from><![CDATA[#^/checkout/cart#]]></from>
                <to>/SpecialCheckout/checkout_cart</to>
            </Company_SpecialCheckout_Checkout_Cart>
        </rewrite>
    </global>
    <frontend>
        <routers>
            <Company_SpecialCheckout>
                <use>standard</use>
                <args>
                    <module>Company_SpecialCheckout</module>
                    <frontName>SpecialCheckout</frontName>
                </args>
            </Company_SpecialCheckout>
        </routers>
    </frontend>
</config>

and then finally the config file in app/etc/modules to make sure the module is picked up.

<?xml version="1.0"?>
<config>
     <modules>
        <Company_SpecialCheckout>
            <active>true</active>
            <codePool>local</codePool>
        </Company_SpecialCheckout>
     </modules>
</config>

then when you go /checkout/cart you should see 'test'. This is based on details I found here.

Make sure you have the cacheing of config files disabled in the Magento admin.

I must admit upfront that I don't have production experience of Magento, but I have spent some time poking around their code.

The block structure is defined in XML, and so you may not need to actually extend the Cart Controller.

The Layout XML files can be found (on a default install) at app/design/frontend/default/default/layout. In here you will find checkout.xml which sets up the block structure for the checkout page.

For those who stuck on this i wrote the simplest way to solve this problem without overloading controllers. My variant based on onepage checkout take a look in magento wiki

It was beeing a nightmare for me, I created a Tutorial in my blog:

CONTROLLER / OVERRIDE / Frontend [...] #^/customer/account/# /mycustomer/account/ [...]

Check this out! How to magento declare and override controllers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top