我正在设计一个带有按钮的自定义产品页面,点击后我需要提示“是”或“否”选项。
如果选择“是”,则需要进行以下操作。
根据产品数量将另一产品添加到购物车中,即在1&之间。 2项添加3&之间的产品A. 4项产品B,介于5和5之间。 12产品C等。
想知道实现这个目标的最佳方法吗?
必须是警报样式弹出窗口(首选ajax弹出窗口)不能是产品页面上的复选框。
谢谢!
答案 0 :(得分:2)
所以我遇到了我的问题的解决方案......我正在使用一个简单的模态(TheBlackBenzKid暗示我)我要么从自定义按钮调用,要么使用添加到购物车按钮。这反过来将重定向到将重定向到购物车的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
我很乐意回答有关此问题的任何问题......
答案 1 :(得分:1)
这不是最佳答案,而是让您入门的代码: 您可以使用购物车功能:
<input type="button" onClick="javascript:nValidateForm();"/>
您的表单代码:
<form name="m2mform" id="m2mform" method="post" onSubmit="javascript:nValidateForm();">
然后只需在页面XML标题中调用外部JavaScript并将其添加到购物车,以便始终检查JS文件并验证弹出窗口。