Announcement

Collapse
No announcement yet.

Quantity of component dependent on choice

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Quantity of component dependent on choice

    I am trying to set up products with components, attributes and choices, where I want to set the quantity ordered figure based on the choice that the customer makes, and this does not seem possible as it stands. For example, I want the customer to select a size, eg Small, Medium or Large, and depending on this selection, a quantity is added to the basket, so 8 for Small, 10 for Medium and 12 for Large. There appears to be only an option in the Component to enter Quantity Used, but I would like this feature to be available for the Choices. Any suggestions?

    I have already set up an Image option for the Choices, following the Advanced User Guide, and guess that I may have to do something similar but I am not expert enough to know what.

    Sarah

    #2
    I don't think there's a way to do this out of the box.

    A possible workaround would be to create some new (perhaps hihden) products "Pack of 8 Easter Eggs", "Pack of 10 Easter Eggs", etc. Then use a dummy product with Permutations to associate each Choice with a pack. Drawback: Not so useful if you need stock control as these new "Pack" products won't deplete the usual stock.

    Another way might be to forget the Choices, and instead create 3 optional Components, "Small", "Medium", "Large", each one using a different number of Associated Products. Drawback: Customer could order none or all 3 selections unless you add some JavaScript to ensure that 1 and only one checkbox is selected when adding to Cart.
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      Thanks, Norman

      Your first suggestion would have been good except we do have to maintain the stock control and we will not be having a huge quantity of stock of any of these products, so that is out.

      Your second suggestion I have already tried but ran into the problem that you state - that they could select two sizes; it doesn't toggle. On further thought overnight, I think the simplest solution is to abandon trying to be clever, and just give the customers a table in the product details of how many items to order for each size.

      Sarah

      Comment


        #4
        Here's how to make a set of Component checkboxes work so that only one can ever be selected. And as a bonus, the product can't be added to cart unless 1 selection is made.

        Locate the Product Layout that you use for such products in Design / Library / Layouts / Products. Right-click it and choose Copy. Rename that layout copy to end in " Only Single Component" (without the quotes).

        Edit that new layout and replace the line:
        Code:
              <form method="post" action="<actinic:variable name="OnlineScriptURL" value="Shopping Cart Script URL" />">
        With:
        Code:
              <form id="cform_<actinic:variable name="EncodedProductAnchor" />" method="post" action="<actinic:variable name="OnlineScriptURL" value="Shopping Cart Script URL" />" onsubmit="return checkcomps(this);">
        Now paste the following into the very top of that layout before anything else:
        Code:
        <script type="text/javascript">
        	function checkcomps(frm){
        		var els = frm.elements;
        		var no_checked = 0;
        		for (i=0; i<els.length; i++)
        			{
        			if ( (els[i].type == 'checkbox') && els[i].checked ) no_checked++;
        			}
        		if ( no_checked != 1 )
        			{
        			alert('You must select one item')
        			return false;
        			}
        		return true;
        	}
        	
        	function allowonlyone(cbox){
        		var els = cbox.form.elements;
        		for (i=0; i<els.length; i++)
        			{
        			if ( (els[i].type == 'checkbox') && (els[i].name != cbox.name) ) els[i].checked = false;
        			}
        	}	
        </script>
        Finally, paste the following into the very bottom of that layout after everything else:
        Code:
        <script type="text/javascript">
        	var els = document.getElementById('cform_<actinic:variable name="EncodedProductAnchor" />').elements;
        	for (i=0; i<els.length; i++)
        		{
        		if ( els[i].type == 'checkbox') els[i].onclick = function(){allowonlyone(this);};
        		}
        </script>
        That's it. Use that new layout only for products with a set of Checkboxes that you want to be mutually exclusive and it will only allow one to be set.

        Make sure that you only set one Component (in Component Details / General) to be "Selected by Default". Usually the first Component but any will do.
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment


          #5
          Thank you.

          Thanks, Norman.

          Sarah

          Comment

          Working...
          X