News:

Support the VirtueMart project and become a member

Main Menu

Custom Field checkbox to add free sample

Started by OliviaH, July 04, 2016, 15:58:53 PM

Previous topic - Next topic

OliviaH

I have been trying to no avail to create a button for a free sample of many of the products on my site.
I first went down the route of making an edited 'add to cart' button that added a set 'Free Sample' product, however I can not figure out how to make it show what product it has come from; I tried to make the 'Free Sample' product's customfield the name or SKU of the main product, however I could not figure out how to. The inner workings of how the data is sent and stored for the cart is beyond my level of knowledge/detective skills.

I am now trying, the perhaps simpler method, of adding a cutomfield to the main product that simply sets the price to 0.00 (0.0001). However so far I have only been able to make the option a radio button that deducts the price from it.
What I want is a checkbox (rather than a radio button) that simply sets the price to 0.0001 (rather than deducting let's say 9.999). This is because I have hundreds of products and setting all those prices will take a very long time and is prone to errors.


So my questions are:

  • How can I make the Custom Field a checkbox rather than radio button.
  • How would I make the custom field a set price rather than it adding/subtracting a value from the price.


Joomla 3.4.8
Virtuemart 3.0.12

GJC Web Design

its a bit hard to understand what you want to do?

2 buttons? 1 product, 1 free sample?
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

OliviaH

Ideally, one button to add a free sample of the product to the cart; so basically another add to cart that would add eg: 'Free Sample: Product 1' to the cart.

GJC Web Design

I do something similar on adding say gift wrapping ..
In your case  link the free sample in some way to the product

e.g. by sku

product sku xxxx
free sample sku free_xxxx

then add a 2nd add to cart button and a query to find the correct product id to use in it

e.g.

$database = JFactory::getDbo();

$queryfindorders = $database->getQuery(true);
$queryfindorders
->select('virtuemart_product_id')
->from($database->quoteName('#__virtuemart_products'))
->where($database->quoteName('product_sku') . '="free_'.$this->virtuemart_product_sku.'"');
$database->setQuery($queryfindorders);
$database->execute();
$freeid = $database->loadResult() ;


code not checked but the idea will work
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

OliviaH

Yeah that's the only way I can figure to do it currently. However adding another 800+ products is using up space that I wanted to avoid using.
There must be a way of changing the data sent to the cart via code. I have a generic 'Free Sample' product with a textinput custom field, wondered if anyone knew how to change what the value of that was with a button and while not on that product. Big ask I know.

GJC Web Design

If u don't want to config the free samples as products you just need to flag in the cart that it is a freebie, not the actual

so as u tried, some sort of custom field.. maybe a hidden chk or radio that is set by JS when the free add to cart is clicked?

or by JS change the pname same to something that tells you he wants the sample -- you need to experiment
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

OliviaH

I hadn't thought of doing the code in the cart, I shall have a play with that.
Cheers

GJC Web Design

no - I meant when it gets to the cart I assume you just need something to tell who ever does the orders that they are requesting a free sample
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

OliviaH

Well I could do that, the problem I am having is making the product price 0 with a custom field, without making each of them deduct the sales price.

OliviaH

I have no idea how to change what data is sent to the cart as I don't know how the data is sent, too advanced for me.

GJC Web Design

as I suggested

if he hits the free sample add to cart change the pname by JS (add "free sample" to it) and submit
in the cart and emails etc display this

or some similar method
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

OliviaH

What I'm saying is I don't know how to change the pname.

GJC Web Design

 I would try by javascript - its just a text in a hidden field.. then submit
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

OliviaH

Oh that yeah, I have tried changing that in the php file, didn't change what was in the cart.

GJC Web Design

FFS, u said u didn't want the cart changed?

you just want to FLAG that they hit the free add to cart button!
so u change something .. detect it at the cart .. render it or display something else so who ever deals with your orders knows its a freebie...
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation