"QTY Matrix" mod - allow bulk ordering of product options

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:

    ```php

    if (empty($REQUEST[‘product_data’][$dispatch_extra][‘amount’])) {

    $REQUEST[‘product_data’][$dispatch_extra][‘amount’] = 1;

    } ```

    and replace it with this

    ```php // QTY MATRIX MOD

    /

    if (empty($REQUEST[‘product_data’][$dispatch_extra][‘amount’])) {

    $REQUEST[‘product_data’][$dispatch_extra][‘amount’] = 1;

    }

    /

    // QTY MATRIX MOD ```



    Now, find:

    ```php fn_add_product_to_cart($_REQUEST[‘product_data’], $cart, $auth); ```

    and replace it with this:

    ```php // 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:

    ```php
    QTY MATRIX MOD *}

    hex }



    {if $po.position <> 999 || $location == “cart” || ($po.position == 999 && !$po.variants)}

    {
    / QTY MATRIX MOD *} ```

    Now, find:

    ```php {elseif $po.option_type == “F”} {File}



    {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}



    {/if} ```

    and paste this directly below that:

    ```php {* QTY MATRIX MOD }

    {else}



    {foreach from=$po.variants item=“vr” name=“vars”}

    {if $vr.modifier|floatval && $show_modifiers}

    {assign var=“price_mod” value=true}

    {/if}

    {/foreach}









    {foreach from=$po.variants item=“vr” name=“vars”}

    {if !$po.disabled || ($po.disabled && $po.value && $po.value == $vr.variant_id)}









    {/if}

    {/foreach}

    {$po.option_name} {$lang.quantity}
    {$vr.variant_name}

    {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}



    {/if}

    {
    / QTY MATRIX MOD } ```

    Now, find this:

    ```php {if $smarty.capture.variant_images|trim}
    {$smarty.capture.variant_images}
    {/if}

    ```

    and replace it with this:

    ```php {
    QTY MATRIX MOD }

    {if $smarty.capture.variant_images|trim && $po.position <> 999}
    {$smarty.capture.variant_images}
    {/if}

    {
    / QTY MATRIX MOD } ```



    Open /skins/yourskin/customer/common_templates/product_data.tpl and find:

    ```php {assign var=“product_amount” value=$product.inventory_amount|default:$product.amount} ```

    and paste this directly below that:

    ```php {
    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:

    ```php {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:

    ```php {if !$qty_matrix}{
    QTY MATRIX MOD } ```

    Now, find this:

    ```php {elseif !$bulk_add} ```

    and paste this directly above that:

    ```php {/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

    QTY_Matrix.jpg

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

qty add.JPG

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

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

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

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



John

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

Chnage the minimum qty to 0 in th eproducts



John

Drew,

You’ll want to use my “QTY Minimums” addon.

Glen

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

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

The product with which I am working is:



[url]http://sg-sys.com/e-store/index.php?dispatch=categories.view&category_id=252[/url]



Drew

Hi,



Have you had a chance to look at this yet?



Best,

Drew


[quote name=‘synergy-gs’]The product with which I am working is:



[url]http://sg-sys.com/e-store/index.php?dispatch=categories.view&category_id=252[/url]



Drew[/QUOTE]

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

Here is a test account.



test@min.com



137yz



Drew

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


[quote name=‘sixnin9’]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[/QUOTE]

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

Glen

[quote name='sixnin9' timestamp='1307991361' post='114908']

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



Glen

[/quote]



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.

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.

[font=“Verdana”]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!

    [/font]