VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: d_a_w_g_y on October 14, 2012, 11:42:09 AM

Title: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
Post by: d_a_w_g_y on October 14, 2012, 11:42:09 AM
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:

<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:

<?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:

<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]
Title: Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
Post by: d_a_w_g_y on October 14, 2012, 21:17:48 PM
I think maybe I should post this:

http://forum.virtuemart.net/index.php?topic=103067.180
Title: Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
Post by: d_a_w_g_y on October 15, 2012, 19:32:03 PM
Hey all, looks like I resolved it, errm .. well i cheated  :P

in stockable.php i did the following:

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
Title: Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
Post by: knapperalpakka 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
Title: Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
Post by: teucg 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:
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.
Title: Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
Post by: adistans on December 27, 2012, 22:05:01 PM
Quote from: teucg 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:
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!
Title: Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
Post by: driver_wedge on January 03, 2013, 00:41:11 AM
I'd also like a bit of information on a solution to this issue. Thanks!!
Title: Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
Post by: VM_Fans on January 03, 2013, 01:26:38 AM
Will this problem occur on VM 2.0.16?
Title: Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
Post by: driver_wedge on January 03, 2013, 20:23:48 PM
Quote from: VM_Fans on January 03, 2013, 01:26:38 AM
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!

Title: Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
Post by: muguet on January 09, 2013, 14:04:53 PM
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
Title: Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
Post by: muguet 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
Title: Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
Post by: chiappa on January 21, 2013, 08:42:06 AM
alright lamers, here you go:

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

Row 399:

var quantity = $(".addtocart-bar .quantity-input").val();

replace:

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


making a backup might be a good idea.
Title: Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
Post by: guidocx842 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!  ;)
Title: Re: VM2.0.20 , Product Details, VM custom stockable variants, undefined in quant
Post by: stoeny on April 09, 2013, 14:07:21 PM
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
Title: Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
Post by: maxispin 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]
Title: Re: VM2.0.12 , Product Details, VM custom stockable variants, undefined issue
Post by: sergio0187 on October 31, 2013, 12:20:50 PM
Hi,

In my case the undefined issue for products with stockable varients disappears when set stock to parent product.
Which didn't have to in previous versions and theoretically not logic.

Another strange thing I came across is that multiple products with stockable varients with stock 1 can be ordered in same order. After order confirmed ordering product varient isn't possible anymore. Shouldn't be possible ordering after adding quantity 1 to cart.