【问题标题】:virtuemart add to cart button in other component美德玛特添加到其他组件中的购物车按钮
【发布时间】:2014-12-22 16:13:46
【问题描述】:

我为 joomla 编写了一个组件,并将它用于美德商城组件。 添加到购物车按钮显示,它也在那里,但我不知道我必须包括什么,我按下他并且产品在购物车中。

这是另一个组件,我只想在其中包含按钮。包含作品,但后面没有功能。

$this->addtocart($product)

查看.html.php

function addtocart ($product) {
        if (!VmConfig::get ('use_as_catalog', 0)) {
            $stockhandle = VmConfig::get ('stockhandle', 'none');
            if (($stockhandle == 'disableit' or $stockhandle == 'disableadd') and ($product->product_in_stock - $product->product_ordered) < 1) {
                $button_lbl = vmText::_ ('COM_VIRTUEMART_CART_NOTIFY');
                $button_cls = 'notify-button';
                $button_name = 'notifycustomer';
                ?>
                <div style="display:inline-block;">
            <a href="<?php echo JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&layout=notify&virtuemart_product_id=' . $product->virtuemart_product_id); ?>" class="notify"><?php echo vmText::_ ('COM_VIRTUEMART_CART_NOTIFY') ?></a>
                </div>
            <?php
            } else {
                $pr_name = $this->getPrDetails($product->virtuemart_product_id, 'product_name');
                $pr_cat = $this->getCat($product->virtuemart_product_id);
                ?>
            <div class="addtocart-area">

                <form method="post" class="product" action="index.php"> 
                    <div class="addtocart-bar">

                        <?php
                        // Add the button
                        $button_lbl = vmText::_ ('COM_VIRTUEMART_CART_ADD_TO');
                        $button_cls = ''; //$button_cls = 'addtocart_button';


                        ?>
                        <?php // Display the add to cart button ?>
                        <span class="addtocart-button">
                            <?php echo shopFunctionsF::getAddToCartButton(true); ?>
            </span>

                        <div class="clear"></div>
                    </div>

                    <input type="hidden" class="pname" value="<?php echo $pr_name ?>"/>
                    <input type="hidden" name="option" value="com_virtuemart"/>
                    <input type="hidden" name="view" value="cart"/>
                    <noscript><input type="hidden" name="task" value="add"/></noscript>
                    <input type="hidden" name="virtuemart_product_id[]" value="<?php echo $product->virtuemart_product_id ?>"/>
                    <input type="hidden" name="virtuemart_category_id[]" value="<?php echo $pr_cat ?>"/>
                </form>
                <div class="clear"></div>
            </div>
            <?php
            }
        }
    }

$product 是表的数组。按钮出现,但我需要后面的功能。我必须为此包括什么?还是不行?

需要帮助,谢谢。

【问题讨论】:

    标签: php joomla include cart virtuemart


    【解决方案1】:

    您展示的这段代码是一个addToCart 函数,它只是为浏览器构建标记。如果您无法将产品实际添加到购物车中,请查看此标记的作用...

    它构建了一个表单,将多个字段发布到 index.html。您需要检查在该 POST 期间发送的值(当您单击添加到购物车按钮时)以及服务器上的相应代码,以查看未添加产品的原因。

    【讨论】:

    • 是的,你是对的。我认为最好的解决方案是编写一个自己的函数,将产品包含在购物车中(数据库条目)。通常之后会从商店中读取它。
    • 我想我的意思是,如果您通过添加到购物车按钮跟踪该 POST 请求的处理,您将能够看到他们是如何创建产品的(已经插入到 db)。
    • 是的。可能我已经为购物车找到了一个功能(添加)。 if (!class_exists('VirtueMartCart')) require(VMPATH_SITE . DS . 'helpers' . DS . 'cart.php'); $cart = VirtueMartCart::getCart();然后你做 $cart->add(Yourstuff) 那说谷歌。但是什么需要Yourstuff?那是什么数组?
    • 只需找到一个现有的添加到购物车的有效按钮,然后逆向工程到执行插入的代码中。
    • 这就是问题所在,我只是在搜索.. 我已经使用调用 $cart->add() 函数的脚本构建了一个 ajax 请求,在头部我给了他产品 ID,但购物车仍然是空的。我必须调用该函数还是更多?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多