News:

Support the VirtueMart project and become a member

Main Menu

Add button to add product sample onto website.

Started by OliviaH, March 18, 2016, 16:37:25 PM

Previous topic - Next topic

OliviaH

Joomla! 3.4.8
Virtuemart 3.0.12
Website: http://www.flooringsales.co.uk/


We have recently changed to a new website, unfortunately the old one is gone and the code seems to be nowhere.

Basically we used to have a button underneath the 'add to cart' button that added a free sample product to the cart, with the product name as an attribute.

We had a uncategorised 'Free Sample' product with sku: FREESAMPLE, so we could control the amount of samples ordered through the shipping method, based of the sku.

I don't really know how or where to code the button into adding this product to the cart, with the sender product as some sort of attribute, so they/we know what product they want a sample of.

Making a sample product for each product is what I want to avoid as we have thousands of products.


Cheers
Dan

Studio 42

Hi Dan,
I think this need a custom development, because you need to use a template change and a plugin, to get the product and add the name in the product.

OliviaH

Well I am looking to do a template override. I just don't know how to add a product to the cart via javascript.
If no one can help I'll keep looking. CUstom development is sadly not an option.

Studio 42

If you don't want use plugin, then you need to declare 2 options.
One is "standard" and one is "free sample" and set the option price to same price as main price but negative
FOr eg if your product price is 10 set option to -10

OliviaH

But if the SKU is that of the product, my shipping method wont work, to ensure only a maximum of 6 samples are allowed on any one order.

Studio 42

For the price, you need then to add a new standard paiment or shipment when all is free.
To add a limit, this need some coding(using a plugin), it's not possible else or of course on hacking Virtuemart.

OliviaH

I am currently using a plugin to do complex shipping methods. But I can't do it based on price as they may have samples and products in the cart.

OliviaH

Well I have worked out how to add a button that adds a set product to the cart.
I created a sublayout that was another 'Add To Cart' button but it adds a set product_id rather than fetching the current one from the page.

<input type="hidden" name="virtuemart_product_id[]" value="3496"/>

I have a custom field on the 'Free Sample' which is currently blank.

Is there a way to change the value of that custom field in the cart with the button?