News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Product Options Custom Field Dropbox Plugin (Updated)

Started by PRO, March 16, 2012, 11:52:11 AM

Previous topic - Next topic

swanson22

Quote from: PRO on April 17, 2013, 15:55:59 PM
Quote from: swanson22 on April 16, 2013, 04:52:07 AM
We downloaded and modified your plugin to act as a multiplier as well but can't seem to find the variable to make the plugin reference the the multipliers we put in instead of multiplying based on base price. Would you happen to know or be able to tell us the variable we need to enter or look for to change this so the plugin will multiply based off of our new multipliers vs. base price. Right now we have it multiplying based off of percents so we use *0.045, 1.275, 0.5 and so on in order to get the correct prices. Any help is much appreciated thanks.

is this what you need?
http://extensions.virtuemart.net/products/custom-size-detail



&&

here is the price function

   public function plgVmCalculateCustomVariant($product, &$productCustomsPrice,$selected){
      if ($productCustomsPrice->custom_element !==$this->_name) return ;
      $customVariant = $this->getCustomVariant($product, $productCustomsPrice,$selected);
      $this->parseCustomParams($productCustomsPrice);
      $productCustomsPrice->custom_price = 0 ;
      if ( isset ($customVariant['custom_drop'])) {
         $options = explode(',', $productCustomsPrice->custom_drop);
         foreach ($options as $valuesWithPrice) {
            $valueWithPrice = explode('|', $valuesWithPrice);

            if ( $customVariant['custom_drop'] == $valueWithPrice[0])  {
               if ( isset ($valueWithPrice[1]) ) {

                  $op = $valueWithPrice[1][0];
                  if ($op == '+') $productCustomsPrice->custom_price =(float) substr($valueWithPrice[1], 1);
                  // testing equals
                  else if ($op == '=') $productCustomsPrice->custom_price = -$product->product_price+(float) substr($valueWithPrice[1], 1);
                  // end test equals
                  else if ($op == '-') $productCustomsPrice->custom_price = -(float) substr($valueWithPrice[1], 1);
                  else $productCustomsPrice->custom_price =(float) $valueWithPrice[1] ;

               }
                  return ;
            }

         }
      }
//          return $field->custom_price;

   }



if you look here

// testing equals
                  else if ($op == '=') $productCustomsPrice->custom_price = -$product->product_price+(float) substr($valueWithPrice[1], 1);
                  // end test equals

You ca see how I subtract the product price & add the equals

So, you should be able to see how to do yours

Thank you. We have figured out how to multiply that variable to the base price, however we want to multiply the variable to the updated price.  We have two product options. The first option multiplies the amount to the base price of the product. The 2nd product option SHOULD multiply to the UPDATED price - NOT the base price. For example:

500 Business Cards are $25.00
Drop down: Quantity  - multiplies based on selection (ex: 1000|*0.9,2000|*1.8,3000|*2.65,4000|*3.5,5000|*4.35)
Drop down: 2 Sided Printing - multiplies based on selection (ex: 1 sided,2 sided|*0.2)
So if the customer wanted 1000 business cards printed on both sides the math would be ==> 25.00 * 0.9 * 0.20

PRO

sounds like you need it all in a single dropdown.

you just need to think it out

swanson22

Quote from: PRO on April 20, 2013, 03:17:16 AM
sounds like you need it all in a single dropdown.

you just need to think it out

We can not do a single drop down because there are too many other options. If you look at most printing websites they are built this way.

We are 99% done and your plugin worked perfectly, we just need the product custom field price variants to multiply the total cost not the base price each time.  Here is what we have:

$op = $valueWithPrice[1][0];
                  // addition
                  if ($op == '+') $productCustomsPrice->custom_price =(float) substr($valueWithPrice[1], 1);
                  // subtraction
                  else if ($op == '-') $productCustomsPrice->custom_price = -(float) substr($valueWithPrice[1], 1);
                  // multiplication
                  else if ($op == '*') $productCustomsPrice->custom_price = *(float) substr($valueWithPrice[1], 1);
                  // equals
                  else if ($op == '=') $productCustomsPrice->custom_price = -$product->product_price+(float) substr($valueWithPrice[1], 1);
                  else $productCustomsPrice->custom_price =(float) $valueWithPrice[1] ;

Instead of using $product->product_price - which just grabs the base price - we want to grab the updated price and multiply the new variable times that.

PRO

Quote from: swanson22 on April 23, 2013, 19:35:32 PM
Quote from: PRO on April 20, 2013, 03:17:16 AM
sounds like you need it all in a single dropdown.

you just need to think it out

We can not do a single drop down because there are too many other options. If you look at most printing websites they are built this way.

We are 99% done and your plugin worked perfectly, we just need the product custom field price variants to multiply the total cost not the base price each time.  Here is what we have:

$op = $valueWithPrice[1][0];
                  // addition
                  if ($op == '+') $productCustomsPrice->custom_price =(float) substr($valueWithPrice[1], 1);
                  // subtraction
                  else if ($op == '-') $productCustomsPrice->custom_price = -(float) substr($valueWithPrice[1], 1);
                  // multiplication
                  else if ($op == '*') $productCustomsPrice->custom_price = *(float) substr($valueWithPrice[1], 1);
                  // equals
                  else if ($op == '=') $productCustomsPrice->custom_price = -$product->product_price+(float) substr($valueWithPrice[1], 1);
                  else $productCustomsPrice->custom_price =(float) $valueWithPrice[1] ;

Instead of using $product->product_price - which just grabs the base price - we want to grab the updated price and multiply the new variable times that.

test a few of these http://forum.virtuemart.net/index.php?topic=104194.0

Thats all I can tell you without having to do a lot of testing.



swanson22

We have 2 different plugins now which would be the drop down plugin and the quantity plugin. What we are wondering now is if there is a way to get the drop box plugin to work with the quantity plugin and can we get the price to change with the quantity plugin? If we can get it to work this way we are golden so we would like to know if this is a possibility. At this point we are willing to invest in plugin to get the results we require and move forward on this project. Both plugins are from the same site so we would just like to know if this is a possibility and how to go about this.

PRO

Quote from: swanson22 on April 29, 2013, 20:34:34 PM
We have 2 different plugins now which would be the drop down plugin and the quantity plugin. What we are wondering now is if there is a way to get the drop box plugin to work with the quantity plugin and can we get the price to change with the quantity plugin? If we can get it to work this way we are golden so we would like to know if this is a possibility. At this point we are willing to invest in plugin to get the results we require and move forward on this project. Both plugins are from the same site so we would just like to know if this is a possibility and how to go about this.

I do not know of a way to do this.

have you done anything with child products?>

realistix

I've been tweaking this plugin to maket he "Add to cart button" disappear unless an option is selected. I realise that this code will only work if there is only one drop box on the page. I'm 99% away from this working but cannot see why it isn't. Perhaps someone could cast their eye over this function? The problem appears to be with obtaining the selected value from the drop box but I'm just putting this together from researching javascript.

$html = JHTML::_('select.genericlist', $selects,'customPlugin['.$field->virtuemart_customfield_id.']['.$this->_name.'][custom_drop]','onchange="drop_change()"','value','text',$selects[0],false,true);

$html .= '<script type="text/javascript">';
$html .= 'document.getElementById("addtocart-button").style.visibility = "hidden";';
$html .= 'function drop_change() {';
$html .= 'var dropelements = document.getElementsByName("customPlugin['.$field->virtuemart_customfield_id.']['.$this->_name.'][custom_drop]");';
$html .= 'var chosenoption = dropelements.options[dropelements.selectedIndex].value; ';
$html .= 'if ( chosenoption == "" ){ document.getElementById("addtocart-button").style.visibility = "hidden" } else { document.getElementById("addtocart-button").style.visibility = "visible" }';
$html .= '}';
$html .= '</script>';

PRO

this code wont work until you modify it



<?php
$document = JFactory::getDocument();
$document->addScriptDeclaration("
   jQuery(document).ready(function($) {
   $('.cart-class').hide();
      $('.select-class').click(function () {
$('.cart-class').show();
});
   });
");
}
?>

realistix

Quote from: PRO on May 08, 2013, 19:33:35 PM
this code wont work until you modify it



<?php
$document = JFactory::getDocument();
$document->addScriptDeclaration("
   jQuery(document).ready(function($) {
   $('.cart-class').hide();
      $('.select-class').click(function () {
$('.cart-class').show();
});
   });
");
}
?>

Hi Pro,

thanks for the reply. Where do I need to put that??

Thanks

PRO

first you need to moodify it to match your add to cart class & your dropbox class


then you can just put it anywhere in the drop.php

BUT remove the php opening & closing


realistix

Ok have done that but getting this error:

Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION

It says it's on line 145:


138       $group->display .= $html;
139
140      return true;
141
142   }
143
144
145 $document = JFactory::getDocument();
146 $document->addScriptDeclaration("
147  jQuery(document).ready(function($) {
148  $('.sun-addtocart-button').hide();
149      $('.dropselect').click(function () {
150 $('.sun-addtocart-button').show();
151 });
152  });
153 ");
154 }

PRO

 $document = JFactory::getDocument();
$document->addScriptDeclaration("
jQuery(document).ready(function($) {
$('.sun-addtocart-button').hide();
$('.dropselect').click(function () {
$('.sun-addtocart-button').show();
   ");   

realistix

Thanks pro,

that modified code would throw an error unless it was within    function plgVmOnDisplayProductVariantFE($field,&$idx,&$group)

Now it doesn't throw an error but the add to cart button still doesn't appear when I select an option that has a value other than ""

PRO

I dont know, I have been trying it.

I cant even get the add to cart button to disappear.


ronjb

Hi has anybody encountered a problem with the dropdown list showing the <strong> tag if a dropdown option has an additional price,,,

just so you know what i'm taking about you can see it here http://turnonled.com.au/index.php/shop-online/54/7/mi-light/tol-mr16-8w-12leds-gu5-3-detail just click the wattage dropdown and you'll see the <strong> tag that i mean,,, any ideas how can i fix this?????? i look on the drop.php and drop.xml and i couldn't find it there,,,


Thanks in advance