Author Topic: Multiple Quantity Question  (Read 43122 times)

Lockerbie

  • Jr. Member
  • **
  • Posts: 102
Re: Multiple Quantity Question
« Reply #15 on: May 30, 2012, 21:34:19 pm »
I'm sorry this is beginning to become some sort of monologue, but this does work!  :D

Yesterday it didn't work at first, but after changing the name of 'default-per-6-flessen.php' to 'per6flessen.php', it did exactly what I wanted!
One thing I forgot, is editting vmsite-ltr.css, in about line 43:
Code: [Select]
span.quantity-controls input.quantity-plus{background:url(../images/vmgeneral/quantity-controls.png) repeat-x;margin-bottom:2px;}
span.quantity-controls input.quantity-minus{background:url(../images/vmgeneral/quantity-controls.png) repeat-x;background-position:15px 0;}
add the new stylenames like this:
Code: [Select]
span.quantity-controls input.quantity-plus,
span.quantity-controls input.quantity-plus6{background:url(../images/vmgeneral/quantity-controls.png) repeat-x;margin-bottom:2px;}
span.quantity-controls input.quantity-minus,
span.quantity-controls input.quantity-minus6{background:url(../images/vmgeneral/quantity-controls.png) repeat-x;background-position:15px 0;}

The only thing now I can't figure out is how to adjust things so, that in the cartpage, the visitor can only add/subtract quantities of 6 products when buying wine in boxes, and he can add/subtract quantities of 1 when buying 'single-bottles-wines'.
Please, is there someone who can help me a bit further with this?

sander_v_bergen

  • Beginner
  • *
  • Posts: 17
Re: Multiple Quantity Question
« Reply #16 on: May 31, 2012, 09:58:50 am »
Hi there,

I'm having the exact same issue. Good to hear that you found (or are on the way of finding) a solution that works for you.

Personaly I don't think that this will work for my webshop. It's a lot of extra work (creating child products, calculating prices, etc.) and a dropdown list 'restricts' you to a max. number (yes you can set the max to 500, but that would be ugly).
Another thing is that you can't change/update the quantity in the cart.

If I find another way I will let you know.

-------------

Regarding the quantity box and plus/minus still being visible:
You can either change this in the default_addtocart.php (components/com_virtuemart/views/productdetails/tmpl/)
or
by adding display:none; in your css (.quantity-controls, .quantity-box{display:none;})

-Sander

Lockerbie

  • Jr. Member
  • **
  • Posts: 102
Re: Multiple Quantity Question
« Reply #17 on: May 31, 2012, 10:11:29 am »
Hello Sander,

I think you misunderstood:
- the quantity box and plus/minus were gone after my editting, but I wanted them to be visible and I solved that by putting the new classnames in vmsite-ltr.css,
- I removed all child products, because I also think it's ugly having all those childproducts (visible when searching on names), and a lot of work! Not to mention al the manual calculation that could easily go wrong when the client wants to add new products and have to do this himself.

All this is why I try to find another solution. I simply can't believe there isn't, but I'm not sure how to solve the latest problem:

Quote
The only thing now I can't figure out is how to adjust things so, that in the cartpage (checkout), the visitor can only add/subtract quantities of 6 products when buying wine in boxes, and he can add/subtract quantities of 1 when buying 'single-bottles-wines'.
Please, is there someone who can help me a bit further with this?

sander_v_bergen

  • Beginner
  • *
  • Posts: 17
Re: Multiple Quantity Question
« Reply #18 on: May 31, 2012, 10:33:48 am »
Hi Lockerbie,

Ok, I see. I did misunderstood you on that ;).

But having multiple product quantity fields seems a bit odd to me (you have the dropdown (6,12,18,etc. and the normal quantity box (1,2,3,4,5,etc.).
Selecting 6 in the dropdown and 2,3,4 in the quantity box also makes 12,18,24. So why display both?

I can't help you with your last question, but I'm still trying to figure something out myself. So if I have a solution I will let you know.

But the first post of this thread by 'team' isn't that hard to fix, since he needs a fix number for all products (10).
Just edit the vmprices.js:

Code: [Select]
plus.click(function() {
var Qtt = parseInt(quantity.val());
if (Qtt != NaN) {
quantity.val(Qtt + 10);
Virtuemart.setproducttype(cart,virtuemart_product_id);
}

});
minus.click(function() {
var Qtt = parseInt(quantity.val());
if (Qtt != NaN && Qtt>10) {
quantity.val(Qtt - 10);
} else quantity.val(10);
Virtuemart.setproducttype(cart,virtuemart_product_id);
});

and then change default_addtocart.php:

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) < 10) {
 
?>

<a href="<?php echo JRoute::_('index.php?option=com_virtuemart&view=productdetails&layout=notify&virtuemart_product_id='.$this->product->virtuemart_product_id); ?>"><?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 
'10';
?>
" />

So basically change all 1 to 10.

EDIT: And you should change the input fields to 'readonly'

Lockerbie

  • Jr. Member
  • **
  • Posts: 102
Re: Multiple Quantity Question
« Reply #19 on: May 31, 2012, 10:43:48 am »
Yep!
But I'm not displaying both options. The dropdown is gone with the child products.
I'm just using 2 different templates for the productdetails-page: 1 for selling single bottles of wine, and 1 for selling wine in boxes of 6 bottles. This last one is used as a page-override.

sander_v_bergen

  • Beginner
  • *
  • Posts: 17
Re: Multiple Quantity Question
« Reply #20 on: May 31, 2012, 14:06:18 pm »
I'm at the exact point as you atm. Everything is working except for the cart page.

I'm considering to completely disable changing quantity in cart, although that wouldn't be user-friendly..
Let me know if you find a solution for this :).

Lockerbie

  • Jr. Member
  • **
  • Posts: 102
Re: Multiple Quantity Question
« Reply #21 on: June 01, 2012, 17:15:45 pm »
So far I've found out things probably have to be adjusted in components/com_virtuemart/views/cart/tmpl/default_pricelist.php
At least, this is where the layout of the cart is build.

I'm looking for a way to solve the quantity-question and/or attach the quantity/updatebuttons from the productdetailspage to the checkoutpage.
This probably means that you'll somehow have to put a clue about some products being sold as single and others as a sixpack (seperate templates again? or something in the default_pricelist.php?), or is this being passed through with all productdetails already? When visiting the checkoutpage after putting a product in the cart, the quantities are right, but the visitor can change them in any chosen number and that's not what we want.

Please, can anyone help me/us a bit further?

Lockerbie

  • Jr. Member
  • **
  • Posts: 102
Re: Multiple Quantity Question
« Reply #22 on: June 02, 2012, 00:49:50 am »
Psst Sander: you can get the minimum quantity active in the cartpage/checkout, simply by changing a class.
In components/com_virtuemart/views/cart/tmpl/default_pricelist.php, about line 152, change:

Code: [Select]
<input type="text" title="<?php echo  JText::_('COM_VIRTUEMART_CART_UPDATE'?>" class="inputbox" size="3" maxlength="4" name="quantity" value="<?php echo $prow->quantity ?>" />
to:

Code: [Select]
<input type="text" title="<?php echo  JText::_('COM_VIRTUEMART_CART_UPDATE'?>" class="quantity-input js-recalculate" size="3" maxlength="4" name="quantity" value="<?php echo $prow->quantity ?>" />
This is working both for quantities of 1 and 6 bottles.

The thing about the arrows, or ordering in sixpacks I still don't get, and I'm afraid I won't find it.
I really hope someone out there could help with this! Please?

Lockerbie

  • Jr. Member
  • **
  • Posts: 102
Re: Multiple Quantity Question
« Reply #23 on: June 03, 2012, 12:25:55 pm »
Okay, same question, different approach...
In VM1 it was possible to use 'Drop down box values': a start, end and a 'step value', see the image I found on the net:



In VM2 there is a 'start value' and an 'end value'. Only thing missing is this 'step value'.
Wouldn't it be possible to add this to the parameters on the product details? And if so: how to do this?

Lockerbie

  • Jr. Member
  • **
  • Posts: 102
Re: Multiple Quantity Question
« Reply #24 on: June 13, 2012, 10:34:45 am »
Still trying to find a solution for this. We really need this, especially since the client has indicated he wants the shipping costs for orders above 24 bottles to be free.
So we do need to 'count' the bottles, not the boxes.

I know what we need, but not how to script this. We need something like:

- if buying single bottles-->number of bottles in cart can be added/subtracted by 1 (already by default),
- if buying wine in boxes of 6 bottles-->number in cart can only be multiplied/divided by 6.

Please, can somebody give me a clue on how to do this?

*********************************************
Edit:
It's been done before: http://www.codingforums.com/showthread.php?t=182466,
Even with VM1, see:   http://forum.virtuemart.net/index.php?topic=51454.0

Now we need just to figure out how to put something like these codes in which files...

yayo76

  • Beginner
  • *
  • Posts: 23
Re: Multiple Quantity Question
« Reply #25 on: June 21, 2012, 10:14:16 am »
Hi Lockerbie,

Ok, I see. I did misunderstood you on that ;).

But having multiple product quantity fields seems a bit odd to me (you have the dropdown (6,12,18,etc. and the normal quantity box (1,2,3,4,5,etc.).
Selecting 6 in the dropdown and 2,3,4 in the quantity box also makes 12,18,24. So why display both?

I can't help you with your last question, but I'm still trying to figure something out myself. So if I have a solution I will let you know.

But the first post of this thread by 'team' isn't that hard to fix, since he needs a fix number for all products (10).
Just edit the vmprices.js:

Code: [Select]
plus.click(function() {
var Qtt = parseInt(quantity.val());
if (Qtt != NaN) {
quantity.val(Qtt + 10);
Virtuemart.setproducttype(cart,virtuemart_product_id);
}

});
minus.click(function() {
var Qtt = parseInt(quantity.val());
if (Qtt != NaN && Qtt>10) {
quantity.val(Qtt - 10);
} else quantity.val(10);
Virtuemart.setproducttype(cart,virtuemart_product_id);
});

and then change default_addtocart.php:

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) < 10) {
 
?>

<a href="<?php echo JRoute::_('index.php?option=com_virtuemart&view=productdetails&layout=notify&virtuemart_product_id='.$this->product->virtuemart_product_id); ?>"><?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 
'10';
?>
" />

So basically change all 1 to 10.

EDIT: And you should change the input fields to 'readonly'

Hi,how I can to set the input field to read only?
thank you.

yayo76

  • Beginner
  • *
  • Posts: 23
Re: Multiple Quantity Question
« Reply #26 on: June 22, 2012, 10:01:25 am »
I solved it:
in the file /components/com_virtuemart/views/productdetails/tmpl/default_addtocart.php line 74 add readonly="readonly" so the field is not editable.

Instead for the cart modify the file in /components/com_virtuemart/views/cart/tmpl/default_pricelist.php line 303 add readonly="readonly" so the field is not editable.

Lockerbie

  • Jr. Member
  • **
  • Posts: 102
Re: Multiple Quantity Question
« Reply #27 on: June 22, 2012, 12:21:33 pm »
Hello Yayo76,

Yes, it could be a solution to set the input field to 'readonly', but I don't think it's very customer friendly... Each time they decide they want another number of products, they have to go back to the shop to add some. Or they have to delete the products from the cart, if they want a number less than they first put in the cart.

***

Perhaps there's another way?
This morning, I got a reply to my question in the VM-LinkedIn-group:

Quote
Abid Hussain • salaam,
 
This is not a readymade solution for virtuemart, but if you can find out the cart page Qty update form : you put in the following javascript and it will do. Insha Allah
 <html>
 <head>
 <title></title>
 <script type="text/javascript">
 function isNumberKey(evt)
 {
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode > 31 && (charCode < 48 || charCode > 57))
 return false;
 
return true;
 }

 function check6(obj) {
 // use the modulus operator '%' to see if there is a remainder
 if (obj.value % 6 != 0) {
 alert('The number you entered is not divisible by 6');
 obj.value = 6;
 return false;
 }
 return true;
 }
 </script>
 <meta name="" content="">
 </head>
 <body>
 <form id="frmQty" action="" method="post">
 <input type="text" onblur="check6(this);" onkeypress="return isNumberKey(event);"/>
 </form>
 </body>
 </html>

Not sure which file this should be put into yet, or in which part, but it looks like we're almost getting there!
I have to go now, will try later. But off course if you'll find it first, please let us know.

Lockerbie

  • Jr. Member
  • **
  • Posts: 102
Re: Multiple Quantity Question
« Reply #28 on: June 25, 2012, 11:30:07 am »
Allright, so far Abid's code seems to work:
I've put his code in default_pricelist.php, and now the number in cart can't be changed to something not divisable by 6 anymore!

Unfortunately, this also counts for the other wines that are sold as singles bottles... Help! How to go further with this?

Lockerbie

  • Jr. Member
  • **
  • Posts: 102
Re: Multiple Quantity Question
« Reply #29 on: June 25, 2012, 17:55:25 pm »
Yep, It's me again... Strange things happen:

1. When using the code above in components/com_virtuemart/views/cart/tmpl/default_pricelist.php (templates/TEMPLATENAME/html/com_virtuemart/cart/default_pricelist.php) this does work, but only when you click the updatebuttons after changing the number. When you click 'enter' instead, the number just changes without any errormessage showing up!
This is the case in FireFox 13.0.1. In IE 9.0.8 the error shows up both when clicking the updatebuttons and 'enter', but after that, the number still does change!
(Perhaps this 'alert'-thing has to be changed into something else?)

2. When using the code above, ALL wines are being sold as 6-packs, which is not the case here. There are some wines that are being sold as single bottles.

As for #2., I tried to solve this by expanding the template (so to say). Instead of default_pricelist.php, I changed this name to 'default_pricelist6.php' and figured out where this file is being called. So I had to change cart/tmpl/default.php and cart/view_html.php too, but got stuck again.

I know (hope) I'm very close, but don't know how it get it all right in the end. And the strange problem with #1. that's a whole other issue.

Please, is there anyone who can help me/us with this?