VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Coding Central => Topic started by: postsingular on March 05, 2015, 17:20:23 PM

Title: Add to cart by SKU
Post by: postsingular on March 05, 2015, 17:20:23 PM
I'm using VM 2.6.6

I'm trying to build a very simple form with only one input field, where users can enter an SKU and add that product to the cart.

I found a piece of code (see below) that works with virtuemart_product_id, but not with an SKU.

Could someone help me modify this code to accept SKUs instead of product IDs?

<form method="post">
<span class="addtocart-button">
<input class="addtocart-button" title="Add to Cart" type="submit" name="addtocart" value="Add to Cart" /> </span>
<input type="hidden" name="quantity[]" value="1" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="view" value="cart" />
<input type="hidden" name="task" value="add" />
<input name="virtuemart_product_id[]" value="1" />
</form>
Title: Re: Add to cart by SKU
Post by: GJC Web Design on March 05, 2015, 23:52:18 PM
2.6.6 is old and unsafe

but back to your question

I guess hack the add() function in components\com_virtuemart\helpers\cart.php to detect when a sku is sent and then look up the corresponding product_id and continue
Title: Re: Add to cart by SKU
Post by: Milbo on March 06, 2015, 16:46:56 PM
then I would also change the table product.php and set the SKU unique as the slug.