0

Good afternoon guys, I'm creating a module to add a product to the magento 1.9 cart, which is outside the site, on an external site. When sending the information from an external server via POST, through my url, I'm getting a no-route-2 error. It works correctly for the same server but not for the external server. How can I resolve this?

My controller

<?php
require_once 'Mage/Checkout/controllers/CartController.php';

class Web_ExternalAddToCart_CartController extends Mage_Checkout_CartController

{
    public function addAction()
    {

        $cart = Mage::helper('checkout/cart')->getCart();

        $key = Mage::getSingleton('core/session')->getFormKey();



        $this->getRequest()->setParams(array('form_key' => Mage::getSingleton('core/session')->getFormKey()));




        $id = $this->getRequest()->getParam('id');

        $id2 = $this->getRequest()->getParam('super_attribute147');

        $id3 = $this->getRequest()->getParam('super_attribute148');


        echo "1";


        $params = array(
            'product' => $id,
            'form_key' => $key,
            'qty' => 1,
            'super_attribute' => array(
                '147' => $id2,
                '148' => $id3
            )

        );



        $product =  Mage::getModel('catalog/product')->load($id);



        try {
            $cart->addProduct($product, $params);
            $cart->save();
            //$this->_redirect('checkout/cart');
        } catch (Exception $e) {

            $this->getResponse()->setBody(Zend_Json::encode($e));
        }
    }
}

My config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Web_ExternalAddToCart>
            <version>1.0.0</version>
        </Web_ExternalAddToCart>
    </modules>
    <frontend>
        <routers>
            <ExternalAddToCart>
                <use>standard</use>
                <args>
                    <module>Web_ExternalAddToCart</module>
                    <frontName>externo</frontName>
                </args>
            </ExternalAddToCart>
        </routers>
    </frontend>


</config>
1
  • Are you able to access the controller-action from a browser? Browser address bar, type: {domain-url}/externo/add?id=123&super_attribute147=small&super_attribute148=green
    – kiatng
    Jul 21 at 6:03

0

Your Answer

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

Browse other questions tagged or ask your own question.