The Configured Products addon forces all child-products to have the same quantity as their parent. The following mod allows you to configure some child-products with a quantity of 1. This could be useful if you sell items that require a setup charge (child qty 1) and a run charge (child qty = parent qty).
Note: This mod repurposes the Product’s Maximum Quantity field. Maximum Quantity alerts will no longer be displayed to the customer. The mod does not use hooks - you will see file conflicts during the next upgrade of CS-Cart. You will need to resolve these conflicts manually. I have only briefly tested the mod - use at your own risk.
The following instructions are for CS-Cart 2.0.14
- Disable the Maximum Quantity alert. In /core/fn.cart.php find
```php fn_set_notification(‘W’, fn_get_lang_var(‘notice’), str_replace(array(‘[product]’ , ‘[quantity]’), array($product[‘product’], $product[‘max_qty’]), fn_get_lang_var(‘text_cart_max_qty’))); ```
and change to
```php //fn_set_notification(‘W’, fn_get_lang_var(‘notice’), str_replace(array(‘[product]’ , ‘[quantity]’), array($product[‘product’], $product[‘max_qty’]), fn_get_lang_var(‘text_cart_max_qty’))); ```
- Make Product Configurator aware of child-item’s max quantity. In /addons/product_configurator/controllers/products.post.php find
```php $_products = db_get_array(“SELECT ?:product_descriptions.product, ?:product_descriptions.product_id , MIN(?:product_prices.price) as price, ?:conf_class_products.class_id, ?:products.tax_ids, ?:products.amount FROM ?:conf_group_products LEFT JOIN ?:products ON ?:products.product_id = ?:conf_group_products.product_id LEFT JOIN ?:product_descriptions ON ?:product_descriptions.product_id = ?:conf_group_products.product_id AND ?:product_descriptions.lang_code = ?s LEFT JOIN ?:product_prices ON ?:product_prices.product_id = ?:product_descriptions.product_id AND ?:product_prices.lower_limit = ‘1’ ?p LEFT JOIN ?:conf_class_products ON ?:conf_class_products.class_id IN (?n) AND ?:conf_class_products.product_id = ?:conf_group_products.product_id ?p WHERE ?:conf_group_products.group_id = ?i AND ?:products.status IN (‘A’, ‘H’) ?p GROUP BY ?:product_prices.product_id ORDER BY ?:product_descriptions.product”, CART_LANGUAGE, $price_usergroup, $class_ids, $join, $v[‘group_id’], $where); ```
and replace it with
```php $_products = db_get_array(“SELECT ?:product_descriptions.product, ?:product_descriptions.product_id , MIN(?:product_prices.price) as price, ?:conf_class_products.class_id, ?:products.tax_ids, ?:products.amount, ?:products.max_qty FROM ?:conf_group_products LEFT JOIN ?:products ON ?:products.product_id = ?:conf_group_products.product_id LEFT JOIN ?:product_descriptions ON ?:product_descriptions.product_id = ?:conf_group_products.product_id AND ?:product_descriptions.lang_code = ?s LEFT JOIN ?:product_prices ON ?:product_prices.product_id = ?:product_descriptions.product_id AND ?:product_prices.lower_limit = ‘1’ ?p LEFT JOIN ?:conf_class_products ON ?:conf_class_products.class_id IN (?n) AND ?:conf_class_products.product_id = ?:conf_group_products.product_id ?p WHERE ?:conf_group_products.group_id = ?i AND ?:products.status IN (‘A’, ‘H’) ?p GROUP BY ?:product_prices.product_id ORDER BY ?:product_descriptions.product”, CART_LANGUAGE, $price_usergroup, $class_ids, $join, $v[‘group_id’], $where); ```
- Modify the math that dynamically updates the product price. In /skins/[yourskin]/customer/addons/product_configurator/hooks/view_main_info.overrride.tpl find
```php conf_prod[{$_group.group_id}][{$_products.product_id}][‘price’] = {$_products.price};
conf_prod[{$_group.group_id}][{$_products.product_id}][‘amount’] = {$_products.amount}; ```
and replace it with
```php {if $_products.max_qty == 0}
conf_prod[{$_group.group_id}][{$_products.product_id}][‘price’] = {$_products.price};
conf_prod[{$_group.group_id}][{$_products.product_id}][‘amount’] = {$_products.amount};
{else}
conf_prod[{$_group.group_id}][{$_products.product_id}][‘price’] = 0;
conf_prod[{$_group.group_id}][{$_products.product_id}][‘amount’] = 1;
{/if} ```
The following steps are optional, but make the subtotals more logical.
- Modify the price display in the cart. In /skins/[yourskin]/customer/addons/product_configurator/hooks/checkout/items_list.overrride.tpl find
```php x {include file=“common_templates/price.tpl” value=$product.display_price span_id=“product_conf_price_$key
” class=“sub-price”} ```
and replace it with
```php x ( {include file=“common_templates/price.tpl” value=$product.display_price span_id=“product_conf_price_$key
” class=“sub-price”}
{foreach from=$cart_products item=“_product” key=“key_conf”}
{if $cart.products.$key_conf.extra.parent.configuration == $key && $_product.max_qty == 0}
- {include file=“common_templates/price.tpl” value=$_product.display_subtotal}
{/if}
{/foreach})
{foreach from=$cart_products item=“_product” key=“key_conf”}
{if $cart.products.$key_conf.extra.parent.configuration == $key && $_product.max_qty != 0}
- {include file=“common_templates/price.tpl” value=$_product.display_subtotal}
{/if}
{/foreach} ```
- Modify the price display in the web invoice. In /skins/[yourskin]/customer/addons/product_configurator/hooks/orders/items_list.overrride.tpl find
```php {include file=“common_templates/price.tpl” value=$conf_price} ```
and replace it with
```php {if $product.extra.exclude_from_calculate}{$lang.free}{else}{include file=“common_templates/price.tpl” value=$product.original_price}{/if} ```
- Modify the price display in the email invoice. In /skins/[yourskin]/mail/addons/product_configurator/hooks/orders/items_list.overrride.tpl find
```php {include file=“common_templates/price.tpl” value=$conf_price|default:0} ```
and replace it with
```php {include file=“common_templates/price.tpl” value=$oi.subtotal|default:0} ```
Mod complete. Now, when I create child-products which should always be qty 1, I simply set their “Maximum order quantity” field to 1. The “Maximum order quantity” cart logic forces the child-product to qty 1 per parent-product.
Cheers,
Glen