News:

Support the VirtueMart project and become a member

Main Menu

Multiple Quantity Question

Started by team, April 26, 2012, 16:27:40 PM

Previous topic - Next topic

Lockerbie

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

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

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:

QuoteThe 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

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


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:


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

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

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

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

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:

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

<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

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

#24
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

Quote from: sander_v_bergen 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:


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:


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

#26
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

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:

QuoteAbid 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

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

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?