Author Topic: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue  (Read 9640 times)

d_a_w_g_y

  • Beginner
  • *
  • Posts: 10
Hi All,

First time posting so hopefully I'm in the right place,

I hope someone can help me with this, I have an odd error that I am trying to track down, I am using productdetails overrides:

TEMPLATE/html/com_virtuemart/productdetails

default.php
default_addtocart.php
default_showprices.php

here is the overview:

1. I added a Custom field of type plugin in virtuemart, VM custom stockable variants, here I added various flavours, e.g. lemon, orange, raspberry etc as a dropdown list.
2. Next I found I had to create some child products, even though I already had these from migration of vm 1.19, anyway not too worried about this, too much DB hacking will probably take more time than actually adding new child products. I like the way I can add different flavours and only use the ones I want to to be mapped to the specific products that I need to have flavours for, or at least it seems this way currently.
3. Next I started testing the functionality, everything seems to works fine, if my products have a quantity greater than 0. I can also add the new child product to the cart.
4.  Until, consider the following example:

  4a. Raspberry has 0 stock, lemon and orange have greater than 0 stock
  4b. I select Raspberry and the Notifyme link appears, which is correct and how I want it to work
  4c. Next I select Lemon, but this time instead of having a value of '1' I have a value of 'undefined', if i refresh my web browser, the value is reset to '1' again (and so is the flavour), in this state of 'undefined' I am unable to add the product to the cart.

Therefore it is the change back from Notifyme to a product that has stock where the problem occurs.

I tracked it down in Firebug to:

Code: [Select]
<div class="addtocart-bar">
<span class="quantity-box">
<input class="quantity-input js-recalculate" type="text" value="undefined" name="quantity[]">
</span>
<span class="quantity-controls js-recalculate">

My default_addtocart.php override for displaying the quantity box looks like:

Code: [Select]
<?php // Display the quantity box

    
$stockhandle VmConfig::get('stockhandle''none');
    if ((
$stockhandle == 'disableit' or $stockhandle == 'disableadd') and ($this->product->product_in_stock $this->product->product_ordered) < 1) {
 
?>

<a href="<?php echo JRoute::_('index.php?option=com_virtuemart&view=productdetails&layout=notify&virtuemart_product_id='.$this->product->virtuemart_product_id); ?>" class="notify"><?php echo JText::_('COM_VIRTUEMART_CART_NOTIFY'?></a>

<?php } else { ?>
<!-- <label for="quantity<?php echo $this->product->virtuemart_product_id?>" class="quantity_box"><?php echo JText::_('COM_VIRTUEMART_CART_QUANTITY'); ?>: </label> -->
   
      <span class="quantity-box">
     
<input type="text" class="quantity-input js-recalculate" name="quantity[]" value="<?php if (isset($this->product->min_order_level) && (int) $this->product->min_order_level 0) {
    echo 
$this->product->min_order_level
} else {
    echo 
'1';
?>
" />

    </span>
    <span class="quantity-controls js-recalculate"> 
<input type="button" class="quantity-controls quantity-plus" />
<input type="button" class="quantity-controls quantity-minus" />
    </span>
   
    <?php // Display the quantity box END ?>


All my products and child products have a minimal purchase quantity of 1 and I have tried changing this override but with not much success, e.g. removed, changed, adapted ;) the following:

Code: [Select]
<input type="text" class="quantity-input js-recalculate" name="quantity[]" value="<?php if (isset($this->product->min_order_level) && (int) $this->product->min_order_level 0) {
    echo 
$this->product->min_order_level
} else {
    echo 
'1';
?>
" />

Maybe I am completely overlooking something, let me know if you need anything else

any help or pointers in the right direction would be most appreciated,

Cheers

d_a_w_g_y

[attachment cleanup by admin]

d_a_w_g_y

  • Beginner
  • *
  • Posts: 10

d_a_w_g_y

  • Beginner
  • *
  • Posts: 10
Hey all, looks like I resolved it, errm .. well i cheated  :P

in stockable.php i did the following:

Code: [Select]
if (quantity == undefined){
            quantity = 1;
          } /* this is the new bit */
$(".addtocart-bar").append(\'<span class="quantity-box"><input type="text" class="quantity-input js-recalculate" name="quantity[]" value="\' + quantity + \'" /></span><span class="quantity-controls js-recalculate"><input type="button" class="quantity-controls quantity-plus" /><input type="button" class="quantity-controls quantity-minus" /></span><span class="addtocart-button"><input type="submit" name="addtocart" class="addtocart-button" value="'.JText::_('COM_VIRTUEMART_CART_ADD_TO').'" title="'.JText::_('COM_VIRTUEMART_CART_ADD_TO').'" /></span><div class="clear"></div>\');
Virtuemart.product($("form.product"));

Can I override this? as i've edited the file direct,

Cheers

d_a_w_g_y

knapperalpakka

  • Beginner
  • *
  • Posts: 13
  • Alpaca enthusiast. Software developer.
    • Alpakkahjemmet Knapper Alpakka
Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
« Reply #3 on: December 16, 2012, 12:04:54 pm »
Have you found a permanent solution for this? I have the exact same issue on VM 2.0.14

teucg

  • Beginner
  • *
  • Posts: 6
    • TEUCG
Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
« Reply #4 on: December 26, 2012, 20:04:04 pm »
I saw your post d_a_w_g_y on your resolve, and I found a more permanent solution to your problem.

Basically, just like the default_addtocart.php makes use of $this->product->min_order_level; to test if this should be the minimal quantity in the quantity field, we should do the same using JSON in stockable.php

This is what I simply did based on your idea:
Code: [Select]
var quantity = $.parseJSON(\'' .json_encode((int)$this->product->min_order_level). '\') ;

if (quantity == 0){
            quantity = 1;
         }

It works great, and I am working on making and alternate VMCUSTOM plugin with a bunch of other improvements implemented.

adistans

  • Beginner
  • *
  • Posts: 1
Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
« Reply #5 on: December 27, 2012, 22:05:01 pm »
I saw your post d_a_w_g_y on your resolve, and I found a more permanent solution to your problem.

Basically, just like the default_addtocart.php makes use of $this->product->min_order_level; to test if this should be the minimal quantity in the quantity field, we should do the same using JSON in stockable.php

This is what I simply did based on your idea:
Code: [Select]
var quantity = $.parseJSON(\'' .json_encode((int)$this->product->min_order_level). '\') ;

if (quantity == 0){
            quantity = 1;
         }

It works great, and I am working on making and alternate VMCUSTOM plugin with a bunch of other improvements implemented.

teucg, could you explain where to insert this piece of code in the stockable.php file? Does it need to replace some code which is already present? Could you specify the line numbers?
I am using VM 2.0.16, and I am getting mad... I have been trying to make it work for several days now without any success, and I was about to give up and go for Hikashop...
Thanks a lot for your help!

driver_wedge

  • Jr. Member
  • **
  • Posts: 58
I'd also like a bit of information on a solution to this issue. Thanks!!

VM_Fans

  • Jr. Member
  • **
  • Posts: 251
Will this problem occur on VM 2.0.16?

driver_wedge

  • Jr. Member
  • **
  • Posts: 58
Will this problem occur on VM 2.0.16?

I'm running 2.0.16 and it does occur with me.

If the guys above could give a bit more information on their solutions (where to insert/change the relevant code) that would be much appreciated!


muguet

  • Beginner
  • *
  • Posts: 8
Hi guys, I add my name to the list of people ready to smash the monitor for the fix of this bug.
Where do we have to add/replace that piece of code please?

thank you

muguet

  • Beginner
  • *
  • Posts: 8
Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
« Reply #10 on: January 10, 2013, 12:41:26 pm »
anyone??????

it's a known bug of VM and nobody posts a solution for it??? It sounds impossible to me...  :o

chiappa

  • Beginner
  • *
  • Posts: 32
Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
« Reply #11 on: January 21, 2013, 08:42:06 am »
alright lamers, here you go:

Quote
/my/boomla/plugins/vmcustom/stockable/stockable.php

Row 399:

Code: [Select]
var quantity = $(".addtocart-bar .quantity-input").val();
replace:

Code: [Select]
var quantity = $.parseJSON(\'' .json_encode((int)$this->product->min_order_level). '\') ;
        if (quantity == 0){
            quantity = 1;
         }

making a backup might be a good idea.

guidocx842

  • Jr. Member
  • **
  • Posts: 74
Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
« Reply #12 on: January 21, 2013, 11:45:21 am »
It works! Thank you very much!
Do you know how can I make an override of this solution?
Because by now I modify directly the file that you suggest but when I'll update the virtuemart version I suppose that this change disappear... right?
Thanks a lot!  ;)

stoeny

  • Beginner
  • *
  • Posts: 8
Dear all,

My first post on this forum :)

I do have the same problem with VM2.0.20, unfortunaly, if i look in stocable on line 399 there is totaly different code.
The code with quantity is around line 800 and in comment.

Pls help, we want to go live soon.

Thanks in advance!

Pascal

maxispin

  • Jr. Member
  • **
  • Posts: 174
Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
« Reply #14 on: October 25, 2013, 09:17:55 am »
This problem exist still on 2.0.24.

If selected e.g., "Displays 'Notify Me' instead of 'Add To Cart' button".
Works with "Products Out of Stock are orderable, no special action"

[attachment cleanup by admin]
VM 3.0.17.6 | VM 2.0.24c | VM 1.1.9