Jump to content

"QTY Matrix" mod - allow bulk ordering of product options Rate Topic   * * * * * 3 votes

 
  • 2020
  • Senior Member
  • Members
  • Join Date: 11-Feb 07
  • 470 posts

Posted 24 May 2011 - 03:01 PM #1

This modification allows customers to enter their desired quantities of each product option variant and then click "add to cart". For instance, when purchasing a shirt available in multiple sizes, the customer may add each desired size to the cart in one step (see the attached screenshot). This especially useful for stores that serve business customers who buy in bulk.

Those interested in this functionality will probably also want to install my "QTY Minimums" addon.

This code is based off of an older addon provided by John Bol (with his permission). It has been tested in CS-Cart 2.1.4 Professional Edition.

Some notes on the functionality:
- "QTY Matrix" layout is triggered when a Product Option has a Position of 999
- don't create more than 1 Product Option with a Position of 999
- only 2 Option Types are supported: Select box, Radio Group
- "QTY Matrix" layout will display wherever an "Add to Cart" button appears (Category, Product Details, Featured Products, etc)
- items in the cart will display the standard Product Option layout
- "QTY Matrix" layout is compatible with Forbidden Combinations

Open /controllers/customer/checkout.php and find:
			if (empty($_REQUEST['product_data'][$dispatch_extra]['amount'])) {
				$_REQUEST['product_data'][$dispatch_extra]['amount'] = 1;
			}
and replace it with this
			// QTY MATRIX MOD
			/*
			if (empty($_REQUEST['product_data'][$dispatch_extra]['amount'])) {
				$_REQUEST['product_data'][$dispatch_extra]['amount'] = 1;
			}
			*/
			// QTY MATRIX MOD

Now, find:
		fn_add_product_to_cart($_REQUEST['product_data'], $cart, $auth);
and replace it with this:
		// QTY MATRIX MOD
		foreach($_REQUEST['product_data'] as $k => $v) {

			$options_a = 0;

			if(!empty($_REQUEST['product_data'][$k]['options_a'])) {
				foreach($_REQUEST['product_data'][$k]['options_a'] as $kk => $vv) {
					If(isset($vv) && $vv != 0) {
						$d_product = array();
						$a = explode('_', $kk);
						$d_product[$k] = $_REQUEST['product_data'][$k];
						$d_product[$k]['product_options'] = array($a[0] => $a[1]);
						if(!empty($_REQUEST['product_data'][$k]['product_options'])) {	
							$d_product[$k]['product_options'] = $d_product[$k]['product_options'] + $_REQUEST['product_data'][$k]['product_options'];
						}	
						$d_product[$k]['amount'] = $vv;
						fn_add_product_to_cart($d_product, $cart, $auth);
						$options_a = 1;
						unset($d_product);
					}

				}
			}

		}

		if(!$options_a) {
			fn_add_product_to_cart($_REQUEST['product_data'], $cart, $auth);
		}
		// /QTY MATRIX MOD

Open /skins/yourskin/customer/views/products/components/product_options.tpl and find:
		<label for="option_{$obj_prefix}{$id}_{$po.option_id}" class="{if $po.required == "Y"}cm-required{/if} {if $po.regexp}cm-regexp{/if}">{$po.option_name}{if $po.description} {capture name="tooltip"}{$po.description}{/capture}{include file="common_templates/tooltip.tpl" tooltip=$smarty.capture.tooltip}{/if}:</label>
and replace it with this:
		{* QTY MATRIX MOD *}
		<label for="option_{$obj_prefix}{$id}_{$po.option_id}" class="{if $po.required == "Y"}cm-required{/if} {if $po.regexp}cm-regexp{/if}">{if $po.position == "999" && $location <> "cart"}{$quantity_text|default:$lang.quantity}{else}{$po.option_name}{/if}{if $po.description} {capture name="tooltip"}{$po.description}{/capture}{include file="common_templates/tooltip.tpl" tooltip=$smarty.capture.tooltip}{/if}:</label>{* hex *}
			
			{if $po.position <> 999 || $location == "cart" || ($po.position == 999 && !$po.variants)} 
		{* / QTY MATRIX MOD *}
Now, find:
		{elseif $po.option_type == "F"} {*File*}
			<div class="clear">
				{include file="common_templates/fileuploader.tpl" images=$product.extra.custom_files[$po.option_id] var_name="`$name`[`$po.option_id``$id`]" multiupload=$po.multiupload hidden_name="`$name`[custom_files][`$po.option_id``$id`]" hidden_value="`$id`_`$po.option_id`" label_id="option_`$obj_prefix``$id`_`$po.option_id`" prefix=$obj_prefix}
			</div>
		{/if}
and paste this directly below that:
			{* QTY MATRIX MOD *}	
			{else}
				<table id="option_{$id}_{$po.option_id}" class="table qty-discounts" cellpadding="0" cellspacing="1" border="0" >
					{foreach from=$po.variants item="vr" name="vars"}
						{if $vr.modifier|floatval && $show_modifiers}
							{assign var="price_mod" value=true}
						{/if}
					{/foreach}
					<tr>
						<th class="center" valign="middle">{$po.option_name}</th>
						<th class="left" valign="middle">{$lang.quantity}</th>
					</tr> 
					{foreach from=$po.variants item="vr" name="vars"}
						{if !$po.disabled || ($po.disabled && $po.value && $po.value == $vr.variant_id)}
							<tr class="{cycle values="dark,light"}">
								<td class="center"><span id="option_description_{$id}_{$po.option_id}_{$vr.variant_id}"><b>{$vr.variant_name}</b></span></td>
								<td class="left"><input type="text" size="5" class="input-text-short" id="qty_count_{$obj_id}" name="product_data[{$obj_id}][options_a][{$po.option_id}_{$vr.variant_id}]" value="0" />
								{if $price_mod}
									{hook name="products:options_modifiers"}{if $vr.modifier|floatval}{include file="common_templates/modifier.tpl" mod_type=$vr.modifier_type mod_value=$vr.modifier display_sign=true}{/if}{/hook}
								{/if}
								</td>
							</tr>
						{/if}
					{/foreach}
				</table>
			{/if}
			{* / QTY MATRIX MOD *}
Now, find this:
		{if $smarty.capture.variant_images|trim}<div class="product-variant-image clear-both">{$smarty.capture.variant_images}</div>{/if}
and replace it with this:
		{* QTY MATRIX MOD *}
		{if $smarty.capture.variant_images|trim && $po.position <> 999}<div class="product-variant-image clear-both">{$smarty.capture.variant_images}</div>{/if}
		{* / QTY MATRIX MOD *}

Open /skins/yourskin/customer/common_templates/product_data.tpl and find:
{assign var="product_amount" value=$product.inventory_amount|default:$product.amount}
and paste this directly below that:
{* QTY MATRIX MOD *}
{foreach from=$product.product_options item="var"}
{if $var.variants && $var.position == 999}
{assign var="qty_matrix" value=true}
{/if}
{/foreach}
{* /QTY MATRIX MOD *}
Now, find:
		{if ($product.qty_content || $show_qty) && $product.is_edp !== "Y" && $cart_button_exists == true && ($settings.General.allow_anonymous_shopping == "Y" || $auth.user_id)}
and paste this directly below that:
			{if !$qty_matrix}{* QTY MATRIX MOD *}
Now, find this:
		{elseif !$bulk_add}
and paste this directly above that:
			{/if}{* /QTY MATRIX MOD *}

That's it. You may want to tweak product_data.tpl some more to move the Quantity Discounts and Minimum Quantity information to more logical positions.

cheers,
Glen

Attached Files


Investigating CS-Cart 4.x

 
  • johnbol1
  • Senior Member
  • Members
  • Join Date: 23-Feb 10
  • 2,997 posts

Posted 24 May 2011 - 05:49 PM #2

Great Stuff Glen, another thing that should be std in the Cart in my opinion.

A couple of issues I get, dunno if you do.
If I have the minimum qty set to say 4 (in this instance) It displays the min qty message twice under the matrix, see pic.
And also when I add 3 to cart, 4 appear in there. If I add 3 to the cart and the min qty is set to 4 then 3 get added and then another 4 =seven.

I appreciate the effort

Thx
John

Attached Files


Custom printed hi vis clothing www.hivis.co.uk the UK's online hivis safety shop
v3.06 - v4.1.5

 
  • 2020
  • Senior Member
  • Members
  • Join Date: 11-Feb 07
  • 470 posts

Posted 24 May 2011 - 06:22 PM #3

John,
Thanks for the bug report. I removed the duplicate Min QTY notice. I'm not sure I follow you regarding the quantities that you are getting in your cart. Unless you have my "QTY Minimum" addon installed, the default behavior of the cart will force the minimum quantity into the cart for each unique product option.
Glen
Investigating CS-Cart 4.x

 
  • johnbol1
  • Senior Member
  • Members
  • Join Date: 23-Feb 10
  • 2,997 posts

Posted 27 May 2011 - 04:58 PM #4

Yes Sorry Glen was a bit unclear there.
Say I have the bulk system setup on half of my products.
When I add any product to the cart that doesnt use the bulk add system, no matter how many I choose to add to the cart, it only ever adds 1. When I change the files back to pre code change it adds correctly.
Is it the same for you?


Thanks

John
Custom printed hi vis clothing www.hivis.co.uk the UK's online hivis safety shop
v3.06 - v4.1.5

 
  • 2020
  • Senior Member
  • Members
  • Join Date: 11-Feb 07
  • 470 posts

Posted 27 May 2011 - 06:52 PM #5

John,
I wasn't able to reproduce the error you're seeing. I have installed this mod on another stock 2.1.4 site using the same steps I describe above and it behaves as expected. Maybe you have another mod or addon on your site that is conflicting with this mod?
Glen
Investigating CS-Cart 4.x

 
  • johnbol1
  • Senior Member
  • Members
  • Join Date: 23-Feb 10
  • 2,997 posts

Posted 28 May 2011 - 08:34 AM #6

Yeah I thought so, I am trying to work through it today, will keep you posted if I find it.

John
Custom printed hi vis clothing www.hivis.co.uk the UK's online hivis safety shop
v3.06 - v4.1.5

 
  • synergy-gs
  • Junior Member
  • Members
  • Join Date: 28-May 11
  • 76 posts

Posted 06 June 2011 - 03:59 PM #7

Hi,

This is a great mod. My only problem is when I try to add my items to card, it does the minimum quantity for each item instead of a total minimum quantity for the item itself. Any ideas?

Best, Drew

 
  • johnbol1
  • Senior Member
  • Members
  • Join Date: 23-Feb 10
  • 2,997 posts

Posted 06 June 2011 - 04:05 PM #8

Chnage the minimum qty to 0 in th eproducts

John
Custom printed hi vis clothing www.hivis.co.uk the UK's online hivis safety shop
v3.06 - v4.1.5

 
  • 2020
  • Senior Member
  • Members
  • Join Date: 11-Feb 07
  • 470 posts

Posted 06 June 2011 - 04:08 PM #9

Drew,
You'll want to use my "QTY Minimums" addon.
Glen
Investigating CS-Cart 4.x

 
  • synergy-gs
  • Junior Member
  • Members
  • Join Date: 28-May 11
  • 76 posts

Posted 06 June 2011 - 04:22 PM #10

Hi again,

I installed it previously according to the following and it adds five of each.
Also, I have revised the other files for the second mod several times, from
the originals, to make certain that I did not miss anything.

First Change: fn_set_hook('check_amount_in_stock', $product_id, $amount, $product_options, $cart_id, $is_edp, $original_amount, $min_qty); // [QTY_MINIMUMS ADDON]
if (isset($current_amount) && $current_amount >= 0 && $current_amount - $amount < 0 && Registry::get('settings.General.allow_negative_amount') != 'Y') {

Second Change: fn_set_notification('W', fn_get_lang_var('notice'), str_replace(array('[product]' , '[quantity]'), array($product['product'] , $min_qty), fn_get_lang_var('text_cart_min_qty')));
if (!defined('ORDER_MANAGEMENT')) {
fn_set_hook('check_amount_in_stock_minimum', $product_id, $amount, $product_options, $cart_id, $is_edp, $original_amount, $min_qty); // [QTY_MINIMUMS ADDON]
$amount = $min_qty;
}

I appreciate your help.

Drew

 
  • 2020
  • Senior Member
  • Members
  • Join Date: 11-Feb 07
  • 470 posts

Posted 07 June 2011 - 02:07 PM #11

Drew,

I'm not clear on your setup, so let me just confirm the following:

Your product has a minimum qty of 5.
You have installed my "QTY Minimums" addon and confirmed that it is working correctly.
You have installed the "QTY Matrix" mod.
Your product now has a Product Option (type: Select or Radio Buttons, postion: 999).
When adding the item to your cart, 5 of each Product Option variation are being added to your cart?

Perhaps you can share a URL for your testing site?

Glen
Investigating CS-Cart 4.x

 
  • synergy-gs
  • Junior Member
  • Members
  • Join Date: 28-May 11
  • 76 posts

Posted 07 June 2011 - 02:38 PM #12

The product with which I am working is:

http://sg-sys.com/e-...category_id=252

Drew

 
  • synergy-gs
  • Junior Member
  • Members
  • Join Date: 28-May 11
  • 76 posts

Posted 09 June 2011 - 08:37 PM #13

Hi,

Have you had a chance to look at this yet?

Best,
Drew

synergy-gs said:

The product with which I am working is:

http://sg-sys.com/e-...category_id=252

Drew


 
  • 2020
  • Senior Member
  • Members
  • Join Date: 11-Feb 07
  • 470 posts

Posted 09 June 2011 - 09:47 PM #14

Drew,

I can't test your site without creating a customer account. I can't create a customer account due to some error with the CAPTCHA (tells me I got it wrong every time). Can you provide a test customer account login?

Glen
Investigating CS-Cart 4.x

 
  • synergy-gs
  • Junior Member
  • Members
  • Join Date: 28-May 11
  • 76 posts

Posted 09 June 2011 - 10:17 PM #15

Here is a test account.

test@min.com

137yz

Drew

 
  • synergy-gs
  • Junior Member
  • Members
  • Join Date: 28-May 11
  • 76 posts

Posted 13 June 2011 - 06:40 PM #16

Hi,

The MIN Quantity add-on was not showing up in my admin Add On section.
I re-inserted all of the code, from both mods, and was able to activate it properly.
Now it works great!

Thank you for you help!

Drew

sixnin9 said:

Drew,

I can't test your site without creating a customer account. I can't create a customer account due to some error with the CAPTCHA (tells me I got it wrong every time). Can you provide a test customer account login?

Glen


 
  • 2020
  • Senior Member
  • Members
  • Join Date: 11-Feb 07
  • 470 posts

Posted 13 June 2011 - 06:56 PM #17

Drew - glad to hear it! Sorry, but I don't have a lot of time to lend support these days.
Glen
Investigating CS-Cart 4.x

 
  • solesurvivor
  • Senior Member
  • Members
  • Join Date: 05-Aug 11
  • 745 posts

Posted 10 August 2011 - 05:25 AM #18

View Postsixnin9, on 13 June 2011 - 06:56 PM, said:

Drew - glad to hear it! Sorry, but I don't have a lot of time to lend support these days.

Glen

Has anyone been able to get this to work with multiple variants? Say if you have three
variants could you output this all in some nice grid? Is this even possible.

 
  • quantex
  • Member
  • Members
  • Join Date: 28-Apr 07
  • 94 posts

Posted 11 October 2011 - 12:16 PM #19

I made the changesand although it puts a nice grid in place it doesn't apply the discounts I have set to the overal cart, for instance if I select 2 of each type across three differnet types it won't apply the discounts to the overal six. If I go to the min breakpoint for any type it will apply the discount but only for that type not the overal basket total, I thought this mod would do it, back to the drawing board I guess.

 

Posted 12 October 2011 - 08:15 PM #20

What a shame this isn't working as expected!

The whole Discounts system in CS-Cart is a complete mess. They need to change the labels and text relating to the whole Discounts component in the system!

Simply have multiple options: If Price > $X, IF QTY > X, IF USER-GROUP = X OR Y OR Z.
The discounts module needs to:
- Allow $ discount or % discount
- Allow recurring on / off
- Applies to a list of products, or a list of categories and list of products.
- Option to set required items before discount is available.
- Start Date of promotion
- End date of promotion
- Number of available times promotion can be used (global users, not per user).
and so on, etc...

The discount system barely covers any of this, as fields are so convoluted and non-meaningful!

If the discounts system COULD WORK with this Bulk Ordering Product Options Addon, then it TRUELY would be great!
:)

If it were working, i'd be happy to pay and support the time spent on the project by the developer.

- Multiple Columns with headers: Combination Name e.g. Blue / Black | Blue / White | Red / White | Red / Yellow
- If size = Out of stock - OR - non-existent in that size -> Disable Cell Input!
- Discount Modifiers may need to be played with - in order to link discounts + promotions to work???

Keen to learn the outcome.
Cheers!

Thank you!