本文介绍了将“添加到购物车"链接而不是按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在category.tpl中,我进行了更改:

In category.tpl I changed:

<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>', '<?php echo $product['minimum']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>

收件人:

<a href="index.php?route=checkout/cart/add&product_id=<?php echo $product['product_id']; ?>&quantity=<?php echo $product['minimum']; ?>" method="get"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></a>

点击添加到购物车"现在将仅使用以下内容加载页面背景:

Clicking Add to Cart now loads the page background, with only:

作为内容.

我正在尝试建立共享"链接,将其复制(例如复制到新闻通讯中)时,单击该链接会自动将该商品添加到您的购物车中.

I am trying to make a 'shareable' link, that when copied (into a newsletter, for example) clicking that link automatically adds the item to your cart.

任何有关如何实现这一目标的建议将不胜感激!

Any suggestions on how to achieve this would be hugely appreciated!

推荐答案

cart.add('<?php echo $product['product_id']; ?>javascript function,用于发送带有ajax POST 方法进行购物.如果您想通过链接执行此操作,则需要使用 GET .

cart.add('<?php echo $product['product_id']; ?> is a javascript function that send product with ajax and POST method to cart.if you want to do this with a link, so you need to use GET.

1),而不是:

<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>', '<?php echo $product['minimum']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>

使用:

<a href="index.php?route=checkout/cart/addToCart&product_id=<?php echo $product['product_id']; ?>"><?php echo $button_cart; ?></a>

2)打开此文件:

catalog/controller/checkout/cart.php

这是与GET一起使用的新function,请将其添加到此文件中:

here is a new function that works with GET, add it to this file:

public function addToCart() {
    $this->load->language('checkout/cart');

    if (isset($this->request->get['product_id'])) {
        $product_id = (int)$this->request->get['product_id'];
    } else {
        $product_id = 0;
    }

    $this->load->model('catalog/product');

    $product_info = $this->model_catalog_product->getProduct($product_id);

    if ($product_info) {
        $this->cart->add($product_id);

        // Display success message
        $this->session->data['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('checkout/cart'));

        //redirect to cart page
        $this->response->redirect($this->url->link('checkout/cart'));
    }
}

这将把产品发送到购物车,尽管这是一个简单的功能,可以添加数量= 1的产品,并且不检查产品选项,但事实就是如此,您可以根据需要进行修改.

this will send product to cart, though this is a simple function that add product with quantity = 1 and doesn't check the product options, but that's the way it is, you can modify it based on your need.

现在,您可以在任何地方共享产品的添加到购物车"链接. (已在最新版本2.3.0.2上进行测试)

Now you can share product's add to cart link anywhere. (tested on latest version 2.3.0.2)

这篇关于将“添加到购物车"链接而不是按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 14:08