我正在设计一个带有按钮的自定义产品页面,当点击时,我需要有一个警报与“是”或“否”选项。
如果选择“是”,那么我需要发生以下事情。
根据产品数量在购物车中添加另一个产品,即在1-2个产品之间添加产品A,在3-4个产品B之间添加产品A,在5- 12个产品C之间添加产品C,依此类推。
你知道实现这一目标的最好方法吗?
它必须是一个警报风格的弹出窗口(ajax弹出窗口首选)不能是产品页面上的复选框。
谢谢!
发布于 2011-11-15 20:22:16
所以我找到了我的问题的解决方案...我使用了一个简单的Modal ( TheBlackBenzKid提示我这样做),我将通过自定义按钮或使用add to cart按钮进行调用。这反过来将重定向到一个php页面,该页面将重定向到购物车。对于php页面,我将只包含将商品放入购物车的代码,任何人都可以想出如何根据自己的需要对其进行定制。
<?php
// Include Magento application (URL to Mage.php)
require_once ( "app/Mage.php" );
umask(0);
//specified quantity my own variable I'm using for quantities
$spqty = 9;
// Initialize Magento
Mage::app("default");
// You have two options here,
// "frontend" for frontend session or "adminhtml" for admin session
Mage::getSingleton("core/session", array("name" => "frontend"));
$session = Mage::getSingleton("customer/session");
// get the current Magento cart
$cart = Mage::getSingleton('checkout/cart');
if ($spqty <= 2) {
// insert item to cart where "98" is the product ID (NOT SKU!) Where "2" is the quantity
$cart->addProduct(98, array('qty' => 2));
} elseif ($spqty >= 4 ){
// you can add multiple products at the same time by adding this line multiple times
$cart->addProduct(96, array('qty' => 3));
}
// save the cart
$cart->save();
// very straightforward, set the cart as updated
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
// redirect to index.php
header("Location: index.php/checkout/cart");我还从这个家伙的博客中找到了一些信息,我会链接到这篇文章
How to add a product from an external site into Magento
我很乐意回答任何关于这方面的问题...
发布于 2011-11-14 17:44:19
这不是最好的答案,但代码可以帮助您入门:您可以让cart函数使用:
<input type="button" onClick="javascript:nValidateForm();"/>和你的表单代码:
<form name="m2mform" id="m2mform" method="post" onSubmit="javascript:nValidateForm();">然后只需调用页面XML头中的外部JavaScript并将其添加到购物车中,这样JS文件将始终被检查并验证弹出窗口。
https://stackoverflow.com/questions/8119613
复制相似问题