Author Topic: Custom Field checkbox to add free sample  (Read 4556 times)

OliviaH

  • Beginner
  • *
  • Posts: 40
Custom Field checkbox to add free sample
« on: July 04, 2016, 15:58:53 pm »
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8892
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.4.2
Re: Custom Field checkbox to add free sample
« Reply #1 on: July 04, 2016, 17:45:07 pm »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

OliviaH

  • Beginner
  • *
  • Posts: 40
Re: Custom Field checkbox to add free sample
« Reply #2 on: July 05, 2016, 10:23:48 am »
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8892
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.4.2
Re: Custom Field checkbox to add free sample
« Reply #3 on: July 05, 2016, 11:06:22 am »
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.

Code: [Select]
$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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

OliviaH

  • Beginner
  • *
  • Posts: 40
Re: Custom Field checkbox to add free sample
« Reply #4 on: July 05, 2016, 11:11:53 am »
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8892
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.4.2
Re: Custom Field checkbox to add free sample
« Reply #5 on: July 05, 2016, 11:19:37 am »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

OliviaH

  • Beginner
  • *
  • Posts: 40
Re: Custom Field checkbox to add free sample
« Reply #6 on: July 05, 2016, 11:35:48 am »
I hadn't thought of doing the code in the cart, I shall have a play with that.
Cheers

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8892
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.4.2
Re: Custom Field checkbox to add free sample
« Reply #7 on: July 05, 2016, 12:26:33 pm »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

OliviaH

  • Beginner
  • *
  • Posts: 40
Re: Custom Field checkbox to add free sample
« Reply #8 on: July 05, 2016, 12:30:21 pm »
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

  • Beginner
  • *
  • Posts: 40
Re: Custom Field checkbox to add free sample
« Reply #9 on: July 05, 2016, 12:31:38 pm »
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8892
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.4.2
Re: Custom Field checkbox to add free sample
« Reply #10 on: July 05, 2016, 13:07:16 pm »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

OliviaH

  • Beginner
  • *
  • Posts: 40
Re: Custom Field checkbox to add free sample
« Reply #11 on: July 05, 2016, 13:31:50 pm »
What I'm saying is I don't know how to change the pname.

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8892
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.4.2
Re: Custom Field checkbox to add free sample
« Reply #12 on: July 05, 2016, 14:40:07 pm »
 I would try by javascript - its just a text in a hidden field.. then submit
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

OliviaH

  • Beginner
  • *
  • Posts: 40
Re: Custom Field checkbox to add free sample
« Reply #13 on: July 05, 2016, 15:10:05 pm »
Oh that yeah, I have tried changing that in the php file, didn't change what was in the cart.

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8892
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.4.2
Re: Custom Field checkbox to add free sample
« Reply #14 on: July 05, 2016, 16:50:22 pm »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation