2011-11-14 47 views
0

我正在設計一個自定義產品頁面,其中包含一個單擊按鈕時我需要提示「Yes」或「No」選項。Magento Auto根據數量添加項目

如果選擇「是」,則需要進行以下操作。

添加另一產品進入車根據1個& 2項之間的產品數量即添加3 & 4項產品B之間的產品A,5 & 12產品C等之間。

任何想法完成此最佳方法?

它必須是一個警報樣式彈出窗口(首選ajax彈出窗口)不能是產品頁面上的複選框。

謝謝!

回答

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

這是不是最好的答案,但代碼,讓你開始: 您可以使購物車功能使用:

<input type="button" onClick="javascript:nValidateForm();"/> 

而且你的表單代碼:

<form name="m2mform" id="m2mform" method="post" onSubmit="javascript:nValidateForm();"> 

然後只需調用在你的頁面XML頭文件中的外部JavaScript並將其添加到購物車,這樣JS文件將被檢查並驗證彈出窗口。

+0

非常感謝您的回覆,Simple Modal Confirm Override看起來像是完美的彈出窗口!然而,如果他們選擇「是」,並且如何根據添加到購物車的前一個物品的數量有條件地執行操作,我確實需要有關將商品自動添加到購物車的語法方面的幫助。 – TravelingAdMan

+0

對不起,這是Magento誤導我的原因之一。它很難做簡單的快速入侵。您可以查看OpenCart MVC基於PHP的購物車,更快,更強大,包括配置和修改代碼。我很抱歉,但我不能再提供幫助。 – TheBlackBenzKid

+0

是的,告訴我...這是客戶想要的,但他們不願意放棄平臺,設計或運營。再次感謝您對模態確認的幫助。這正是我需要的。 – TravelingAdMan