Manual

relations.class.php

Market products relations management

Usage:

{{lang:php}}
// INITIALIZATION
$rel = new relations($DB); // $DB is the object from sql class

// MANAGE RELATIONS
$product_iid = 11;
$related_iid = 22;
$priority = 1; // optional, default 0
$rel->relate($product_iid, $related_iid, $priority); // relates two products by IID (with priority)
$rel->set_priority ($product_iid, $related_iid, 1) // sets or unsets priority (3rd parameter 1 or 0)    

$array = array(1, 2, 3, 4, 7, 9, 10); // products IIDs
$rel->relate_array($array); // relates all products together with each other

$rel->separate ($product_iid, $related_iid); // deletes relation between two products
$rel->remove($product_iid); // removes product from all possible relations

$rel->remove_all_relations(); // truncates table market_relations

// GETTING RESULTS
$rel->get_related_iids($product_iid); // returns array (0 => '1,2,3,4', 1=>'5,6,7,8') where keys are priority and values are IIDs separated by commas

// get_related_products($product_iid, $lang, $order_priority_1='', $order_priority_0='');
$rel->get_related_products(27, 'en', 'price', 'id DESC'); // gets total products array ordered separately by priorities
Try myPortal 2: