Search code examples
phpjoomlashopping-cartvirtuemart

Virtuemart Repeat Order


The thing is that I would like to implement the following functionality to my site: In the account settings - order details I would like to add a button that would add all the products from that very order to cart. Now, I pretty much get it how the add to cart functionality is implemented on the flypage and browse page. I can't really get how should I pass multiple items to the add to cart function on order details page and how it'll be processed by ps_cart if an item is out of stock or is unpublished. Here's the code of the add to cart form from browse page:

<form action="<?php echo $mm_action_url ?>index.php" method="post" name="addtocart" id="addtocart<?php echo $i ?>" class="addtocart_form" <?php if( $this->get_cfg( 'useAjaxCartActions', 1 ) && !$notify ) { echo 'onsubmit="handleAddToCart( this.id );return false;"'; } ?>>
    <?php echo $ps_product_attribute->show_quantity_box($product_id,$product_id); ?><br />
    <input type="submit" class="<?php echo $button_cls ?>" value="<?php echo $button_lbl    ?>" title="<?php echo $button_lbl ?>" />
    <input type="hidden" name="category_id" value="<?php echo  @$_REQUEST['category_id'] ?>" />
    <input type="hidden" name="product_id" value="<?php echo $product_id ?>" />
    <input type="hidden" name="prod_id[]" value="<?php echo $product_id ?>" />
    <input type="hidden" name="page" value="shop.cart" />
    <input type="hidden" name="func" value="cartadd" />
    <input type="hidden" name="Itemid" value="<?php echo $sess->getShopItemid() ?>" />
    <input type="hidden" name="option" value="com_virtuemart" />
    <input type="hidden" name="set_price[]" value="" />
    <input type="hidden" name="adjust_price[]" value="" />
    <input type="hidden" name="master_product[]" value="" />
</form>

I wonder if I'd need to pass all of these to ps_cart? I don't expect from any of you a completely ready extension, it would be great if you could point me in the right direction. Thanks!

EDIT: I was able to set up the add to cart button, now I have to pass the needed data. It would be great if it would work with at least one item, then I'd start thinking how to alter the code.

EDIT 2: I was able to make it work flawlessly for one product. But how can I pass multiple Product Id's and their quantities to the add to cart function?


Solution

  • The current code in ps_cart already has a loop to iterate through multiple product IDs that are sent to the cart. From the look of the code there, I would simple put all of the product IDs you want to add to the cart in to prod_id array. You will notice that prod_id, set_price, adjust_price, and master_product are all arrays in the form. My guess is that you will need to put in those values for each product you want to add and ps_cart will do the rest.