В код типой динамической страницы интернет-магазина, перед блоком с ->show()
, добавьте приведенный ниже код. Диапозон цен задается в переменной $coef
, в данном примере он составляет 10%. Похожие по цене товары пойдут в XML карточки товара в тег <same_items>
if ($Shop_Controller_Show->item)
{
$coef = 0.1;
$oXmlSameItems = Core::factory('Core_Xml_Entity')->name('same_items');
$Shop_Controller_Show->addEntity($oXmlSameItems);
$oShop = $Shop_Controller_Show->getEntity();
$oCurItem = Core_Entity::factory('Shop_Item', $Shop_Controller_Show->item);
$delta = floatval($oCurItem->price) * $coef;
$maxPrice = $oCurItem->price + $delta;
$minPrice = $oCurItem->price - $delta;
$oShop_Same_Items = $oShop->Shop_Items;
$oShop_Same_Items
->queryBuilder()
->where('shop_items.id', '!=', intval($oCurItem->id))
->where('shop_items.active', '=', 1)
->where('shop_items.price', 'BETWEEN', array($minPrice, $maxPrice))
->limit(10)
->clearOrderBy()
->orderBy('RAND()');
$aShop_Same_Items = $oShop_Same_Items->findAll();
foreach($aShop_Same_Items as $oShop_Same_Item)
{
$oXmlSameItems->addEntity(
$oShop_Same_Item->clearEntities()
);
}
}