// js
function fieldAddToCart(productId)
{
var url = '/magento/index.php/fieldcatalog/product/add';
var pars = 'id='+productId;
var myAjax = new Ajax.Request(
url,
{
method:'get',
parameters:pars,
onComplete:showResponse
});
}
function showResponse(x)
{
if(x.responseText == 'success'){
window.location.reload();
}else {
alert('add to cart failed')
}
}
//
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_Catalog
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
require_once "Mage/Catalog/controllers/ProductController.php";
/**
* Product controller
*
* @category Mage
* @package Mage_Catalog
*/
class Field_Catalog_ProductController extends Mage_Catalog_ProductController
{
public function indexAction()
{
echo 'hello';
}
protected function _initProduct()
{
$productId = (int) $this->getRequest()->getParam('id');
if ($productId) {
$product = Mage::getModel('catalog/product')
->setStoreId(Mage::app()->getStore()->getId())
->load($productId);
if ($product->getId()) {
return $product;
}
}
return false;
}
public function addAction()
{
$cart = Mage::getSingleton('checkout/cart');
$params = $this->getRequest()->getParams('id');
$product= $this->_initProduct();
$cart->addProduct($product, $params);
if($cart->save()){
echo 'success';
}else {
echo 'failed';
}
//var_dump($cart);
}
}
//
<?xml version="1.0"?>
<!--
/**
*
* @category Field
* @package Field_Catalog
*
*/
-->
<config>
<modules>
<Field_Catalog>
<version>0.1.0</version>
</Field_Catalog>
</modules>
<global>
<blocks>
<catalog>
<rewrite>
<product_list>Field_Catalog_Block_Product_List</product_list>
</rewrite>
</catalog>
</blocks>
</global>
<frontend>
<routers>
<Field_catalog>
<use>standard</use>
<args>
<module>Field_Catalog</module>
<frontName>fieldcatalog</frontName>
</args>
</Field_catalog>
</routers>
</frontend>
</config>
//<?xml version="1.0"?>
<config>
<modules>
<Field_Catalog>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Catalog />
</depends>
</Field_Catalog>
</modules>
</config>
function fieldAddToCart(productId)
{
var url = '/magento/index.php/fieldcatalog/product/add';
var pars = 'id='+productId;
var myAjax = new Ajax.Request(
url,
{
method:'get',
parameters:pars,
onComplete:showResponse
});
}
function showResponse(x)
{
if(x.responseText == 'success'){
window.location.reload();
}else {
alert('add to cart failed')
}
}
//
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_Catalog
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
require_once "Mage/Catalog/controllers/ProductController.php";
/**
* Product controller
*
* @category Mage
* @package Mage_Catalog
*/
class Field_Catalog_ProductController extends Mage_Catalog_ProductController
{
public function indexAction()
{
echo 'hello';
}
protected function _initProduct()
{
$productId = (int) $this->getRequest()->getParam('id');
if ($productId) {
$product = Mage::getModel('catalog/product')
->setStoreId(Mage::app()->getStore()->getId())
->load($productId);
if ($product->getId()) {
return $product;
}
}
return false;
}
public function addAction()
{
$cart = Mage::getSingleton('checkout/cart');
$params = $this->getRequest()->getParams('id');
$product= $this->_initProduct();
$cart->addProduct($product, $params);
if($cart->save()){
echo 'success';
}else {
echo 'failed';
}
//var_dump($cart);
}
}
//
<?xml version="1.0"?>
<!--
/**
*
* @category Field
* @package Field_Catalog
*
*/
-->
<config>
<modules>
<Field_Catalog>
<version>0.1.0</version>
</Field_Catalog>
</modules>
<global>
<blocks>
<catalog>
<rewrite>
<product_list>Field_Catalog_Block_Product_List</product_list>
</rewrite>
</catalog>
</blocks>
</global>
<frontend>
<routers>
<Field_catalog>
<use>standard</use>
<args>
<module>Field_Catalog</module>
<frontName>fieldcatalog</frontName>
</args>
</Field_catalog>
</routers>
</frontend>
</config>
//<?xml version="1.0"?>
<config>
<modules>
<Field_Catalog>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Catalog />
</depends>
</Field_Catalog>
</modules>
</config>