简体   繁体   中英

virtuemart add to cart button in other component

i write an component for joomla and i use it for the virtuemart Shop component. The Add To cart button shows, it's also there, but i don't know what i must include, that i press him and the Product is in the cart.

It's another component, i just want to include the button in their. Include works, but there is no function behind.

$this->addtocart($product)

View.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 is an array of the table. Button shows up, but i need the function behind. What i must include for this? Or does it not work?

Need help, thanks.

This code you have shown is an addToCart function that just builds markup for the browser. If you're having trouble getting it to actually add a product to the cart, look at what this markup does...

It builds a form which posts several fields to index.html . You'll need to inspect the values being sent during that POST (when you click the add to cart button) and the corresponding code on the server to see why a product isn't getting added.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM