美德市场添加到购物车按钮在其他组件中


virtuemart add to cart button in other component

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

这是另一个组件,我只想将按钮包含在他们的组件中。包括作品,但背后没有功能。

$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是表的数组。按钮出现,但我需要后面的功能。为此我必须包括什么?还是不起作用?

需要帮助,谢谢。

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

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