mys

// 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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值