Javascript magento通过复选框将多个产品从愿望列表添加到购物车
场景:Javascript magento通过复选框将多个产品从愿望列表添加到购物车,javascript,magento,cart,Javascript,Magento,Cart,场景:希望通过复选框将多个产品从愿望列表添加到购物车,以便将所选产品及其数量转移到购物车,并从愿望列表表中删除所选项目。 参考了许多博客。 我试图通过(应用)添加相关产品javascript(逻辑)来实现它。但仍然没有得到。 [更新] 这是复选框列(暂时为硬代码) 为该部分添加了Javascript: <script type="text/javascript"> //<![CDATA[ $$('.related-checkbox').each(functi
希望通过复选框将多个产品从愿望列表添加到购物车,以便将所选产品及其数量转移到购物车,并从愿望列表表中删除所选项目。
参考了许多博客。
我试图通过(应用)添加相关产品javascript(逻辑)来实现它。
但仍然没有得到。
[更新] 这是复选框列(暂时为硬代码)
为该部分添加了Javascript:
<script type="text/javascript">
//<![CDATA[
$$('.related-checkbox').each(function(elem){
Event.observe(elem, 'click', addRelatedToProduct)
});
var relatedProductsCheckFlag = false;
function selectAllRelated(txt){
if (relatedProductsCheckFlag == false) {
$$('.related-checkbox').each(function(elem){
elem.checked = true;
});
relatedProductsCheckFlag = true;
txt.innerHTML="unselect all";
} else {
$$('.related-checkbox').each(function(elem){
elem.checked = false;
});
relatedProductsCheckFlag = false;
txt.innerHTML="select all";
}
addRelatedToProduct();
}
function addRelatedToProduct(){
var checkboxes = $$('.related-checkbox');
var values = [];
for(var i=0;i<checkboxes.length;i++){
if(checkboxes[i].checked) values.push(checkboxes[i].value);
}
if($('related-products-field')){
$('related-products-field').value = values.join(',');
}
}
//]]>
</script>
//
添加到购物车添加到购物车
这部分的javascript:<script type="text/javascript">
//<![CDATA[
var productAddToCartForm = new VarienForm('product_addtocart_form');
productAddToCartForm.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
try {
this.form.submit();
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}
if (button && button != 'undefined') {
button.disabled = true;
}
}
}.bind(productAddToCartForm);
productAddToCartForm.submitLight = function(button, url){
if(this.validator) {
var nv = Validation.methods;
delete Validation.methods['required-entry'];
delete Validation.methods['validate-one-required'];
delete Validation.methods['validate-one-required-by-name'];
// Remove custom datetime validators
for (var methodName in Validation.methods) {
if (methodName.match(/^validate-datetime-.*/i)) {
delete Validation.methods[methodName];
}
}
if (this.validator.validate()) {
if (url) {
this.form.action = url;
}
this.form.submit();
}
Object.extend(Validation.methods, nv);
}
}.bind(productAddToCartForm);
//]]>
</script>
//
提前感谢单击(将所有内容添加到购物车)表单操作将转到本部分此处的/wishlist/update部分。
添加updatenew函数并添加以下代码
public function updatenewAction()
{
$post = $this->getRequest()->getPost();
$product_id = $qtyarr=array();
$product_id = $this->getRequest()->getPost('product123');
$qtyarr = $this->getRequest()->getPost('qty');
if($product_id)
{
$procol = Mage::getModel('catalog/product');
$cart = Mage::getModel('checkout/cart');
foreach($product_id as $productid => $wishlistid)
{
$proid = $procol->load($productid);
$_product = $procol->load($productid);
$proname = $procol->getName();
$quantity = $qtyarr[$wishlistid] ;
$cart->init();
$cart->addProduct($productid,$quantity);
$cart->save();
Mage::getSingleton('core/session')->addSuccess($proname.' moved from Wishlist');
Mage::getModel('wishlist/item')->load($wishlistid)->delete();
}
return $this->_redirectUrl(Mage::helper('checkout/cart')->getCartUrl());
}
else
{
Mage::getSingleton('core/session')->addError('No Product Selected');
$this->_redirect('wishlist');
}
}
在上面的代码中,我们以编程方式将产品添加到购物车中,同时将其从愿望列表中删除。default/template/wishlist/item/column/image.phtml
<input type="checkbox" class="checkbox related-checkbox" id="related-checkbox<?php echo $product->getId()?>" name="product123[<?php echo $product->getId() ?>]" value="<?php echo $item->getId() ?>" />
单击(将所有内容添加到购物车)表单操作将转到本部分此处的/wishlist/update部分。
添加updatenew函数并添加以下代码
public function updatenewAction()
{
$post = $this->getRequest()->getPost();
$product_id = $qtyarr=array();
$product_id = $this->getRequest()->getPost('product123');
$qtyarr = $this->getRequest()->getPost('qty');
if($product_id)
{
$procol = Mage::getModel('catalog/product');
$cart = Mage::getModel('checkout/cart');
foreach($product_id as $productid => $wishlistid)
{
$proid = $procol->load($productid);
$_product = $procol->load($productid);
$proname = $procol->getName();
$quantity = $qtyarr[$wishlistid] ;
$cart->init();
$cart->addProduct($productid,$quantity);
$cart->save();
Mage::getSingleton('core/session')->addSuccess($proname.' moved from Wishlist');
Mage::getModel('wishlist/item')->load($wishlistid)->delete();
}
return $this->_redirectUrl(Mage::helper('checkout/cart')->getCartUrl());
}
else
{
Mage::getSingleton('core/session')->addError('No Product Selected');
$this->_redirect('wishlist');
}
}
在上面的代码中,我们以编程方式将产品添加到购物车中,同时将其从愿望列表中删除。
default/template/wishlist/item/column/image.phtml
<input type="checkbox" class="checkbox related-checkbox" id="related-checkbox<?php echo $product->getId()?>" name="product123[<?php echo $product->getId() ?>]" value="<?php echo $item->getId() ?>" />
给我们一些工作代码on@AkhilSekharan知道如何实现吗?给我们一些代码on@AkhilSekharan你知道如何实施吗?