Magento Custom Module. Redirect to another module and return to checkout


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.

1
0
9/25/2015 8:09:30 AM

Accepted Answer

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

1
5/19/2009 6:08:31 AM

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.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon