Simple way to show buy together tab on all products from combination

Hi there fellow members,



ex: prod 1 have combination: prod 1 + prod 2 + prod 3 = X price

Buy Together tab will appear only on prod 1 and with the trick bellow will appear also on prod 2 and prod 3



for this you need to add in file [color=#0000ff]addons/buy_together/func.php[/color]



after:


$chains = db_get_array("SELECT $fields FROM ?:buy_together AS items LEFT JOIN ?:products AS p ON p.product_id = items.product_id LEFT JOIN ?:buy_together_descriptions AS descr ON items.chain_id = descr.chain_id AND descr.lang_code = ?s $condition", $lang_code);




add:


//add by hungryweb.net ****************************************************************
if (empty($chains) && AREA == 'C') {
if (!empty($params['product_id'])){
$conditions[0] = 'products LIKE \'%product_id";s:'.strlen($params['product_id']).':"'.$params['product_id'].'"%\'';
}
$condition = 'WHERE ' . implode(' AND ', $conditions);
$chains = db_get_array("SELECT $fields FROM ?:buy_together AS items LEFT JOIN ?:products AS p ON p.product_id = items.product_id LEFT JOIN ?:buy_together_descriptions AS descr ON items.chain_id = descr.chain_id AND descr.lang_code = ?s $condition", $lang_code);
}
//end *****************************************************************************************




Tested on v3.0.6



I hope that helps,





Valentin

This has been an annoyance in the Buy Together addon from the beginning. Thanks for the fix.

[quote name='Vali' timestamp='1364848685' post='159110']

Hi there fellow members,



ex: prod 1 have combination: prod 1 + prod 2 + prod 3 = X price

Buy Together tab will appear only on prod 1 and with the trick bellow will appear also on prod 2 and prod 3



for this you need to add in file [color=#0000FF]addons/buy_together/func.php[/color]



after:


$chains = db_get_array("SELECT $fields FROM ?:buy_together AS items LEFT JOIN ?:products AS p ON p.product_id = items.product_id LEFT JOIN ?:buy_together_descriptions AS descr ON items.chain_id = descr.chain_id AND descr.lang_code = ?s $condition", $lang_code);




add:


//add by hungryweb.net ****************************************************************
if (empty($chains) && AREA == 'C') {
if (!empty($params['product_id'])){
$conditions[0] = 'products LIKE \'%product_id";s:'.strlen($params['product_id']).':"'.$params['product_id'].'"%\'';
}
$condition = 'WHERE ' . implode(' AND ', $conditions);
$chains = db_get_array("SELECT $fields FROM ?:buy_together AS items LEFT JOIN ?:products AS p ON p.product_id = items.product_id LEFT JOIN ?:buy_together_descriptions AS descr ON items.chain_id = descr.chain_id AND descr.lang_code = ?s $condition", $lang_code);
}
//end *****************************************************************************************




Tested on v3.0.6



I hope that helps,





Valentin

[/quote]Thanks

You're welcome

[quote name='Vali' timestamp='1364848685' post='159110']

Hi there fellow members,



ex: prod 1 have combination: prod 1 + prod 2 + prod 3 = X price

Buy Together tab will appear only on prod 1 and with the trick bellow will appear also on prod 2 and prod 3



for this you need to add in file [color=#0000ff]addons/buy_together/func.php[/color]



after:


$chains = db_get_array("SELECT $fields FROM ?:buy_together AS items LEFT JOIN ?:products AS p ON p.product_id = items.product_id LEFT JOIN ?:buy_together_descriptions AS descr ON items.chain_id = descr.chain_id AND descr.lang_code = ?s $condition", $lang_code);




add:


//add by hungryweb.net ****************************************************************
if (empty($chains) && AREA == 'C') {
if (!empty($params['product_id'])){
$conditions[0] = 'products LIKE \'%product_id";s:'.strlen($params['product_id']).':"'.$params['product_id'].'"%\'';
}
$condition = 'WHERE ' . implode(' AND ', $conditions);
$chains = db_get_array("SELECT $fields FROM ?:buy_together AS items LEFT JOIN ?:products AS p ON p.product_id = items.product_id LEFT JOIN ?:buy_together_descriptions AS descr ON items.chain_id = descr.chain_id AND descr.lang_code = ?s $condition", $lang_code);
}
//end *****************************************************************************************




Tested on v3.0.6



I hope that helps,





Valentin

[/quote]



Added & working on MV v.4.2.4. Thank you so much!

Update for CS-Cart 4.3.6

#file

addons/buy_together/func.php
#after:
$chains = db_get_array(“SELECT {$fields} FROM ?:buy_together AS items {$joins} {$condition}”);
#add:
//add by hungryweb.net ****************************************************************
if (empty($chains) && AREA == ‘C’) {
if (!empty($params[‘product_id’])){
$conditions[‘product_id’] = ‘products LIKE '%“product_id”;s:’.strlen($params[‘product_id’]).‘:"’.$params[‘product_id’].‘"%'’;
}
$condition = ‘WHERE ’ . implode(’ AND ', $conditions);
$chains = db_get_array(“SELECT {$fields} FROM ?:buy_together AS items {$joins} {$condition}”);
}
//end *********************************************************************************
Tested on v4.3.6

I hope that helps,


Valentin

There are also now buy_together_get_chains_pre, buy_together_get_chains_post and buy_together_get_chains hooks for chain manipulation in the buy_together addon.
Using them means you don’t end up with a modified distributed file to remember at next upgrade.

Thank you @tbirnseth for your notice and push :)

Please add in :

1.

#file

app/addons/my_changes/init.php

#content

if (!defined(‘BOOTSTRAP’)) { die(‘Access denied’); }

fn_register_hooks(
‘buy_together_get_chains’
);

2.

#file

app/addons/my_changes/func.php

#content

if (!defined(‘BOOTSTRAP’)) { die(‘Access denied’); }

function fn_my_changes_buy_together_get_chains($params, $auth, $lang_code, $fields, &$conditions, $joins){
if (AREA == ‘C’ && !empty($conditions[‘product_id’])) {
$condition = ‘WHERE ’ . implode(’ AND ‘, $conditions);
$fields = implode(’, ‘, $fields);
$joins = implode(’ ', $joins);

	$chains = db_get_array("SELECT {$fields} FROM ?:buy_together AS items {$joins} {$condition}");
	if(empty($chains)){
		$conditions['product_id'] = 'products LIKE \'%"product_id";s:'.strlen($params['product_id']).':"'.$params['product_id'].'"%\'';
	}
}

}

* My Changes add-on is required to be active for this to work

* If the folder structure is missing you need to create

* This modification will require a extra mysql query but should not affect in any way website speed

I hope that helps,

---
Valentin
part of hungryweb.net

Thank you @tbirnseth for your notice and push :)

Sometimes a bit more work up front, but huge time (and frustration) savings in the long term (until they change the hook of course!)