А тут такой вопрос возник,
надо выбирать товары из магазина по двум-трем-четырем-пяти и тд. свойствам, причем товар должен обладать всеми заданными свойствами, я тут полазил по форумы и ничего не нашёл, пробовал примеры, но увы не получается, пытался разобратся с кодом интрнет-магазина (ТДС), но тоже не получилось.
У меня код выглядит сейчас так. Я не понимаю всех тонкостей mysql, прошу направить на путь истинный.
$Shop_Controller_Show = new Shop_Controller_Show(
Core_Entity::factory('Shop', 2)
);
$Shop_Controller_Show
->xsl(
Core_Entity::factory('Xsl')->getByName('СписокОбъявлений')
)
->groupsMode('none')
->limit(50)
->itemsProperties(TRUE)
->group(false);
$Shop_Controller_Show->shopItems()->queryBuilder()
->leftJoin('shop_item_properties', 'shop_items.shop_id', '=', 'shop_item_properties.shop_id')
->leftJoin('property_value_ints', 'shop_items.id', '=', 'property_value_ints.entity_id',
array(
array('AND' => array('shop_item_properties.property_id', '=',
Core_QueryBuilder::expression('`property_value_ints`.`property_id`')))
)
)
->leftJoin('property_value_files', 'shop_items.id', '=', 'property_value_files.entity_id',
array(
array('AND' => array('shop_item_properties.property_id', '=',
Core_QueryBuilder::expression('`property_value_files`.`property_id`')))
)
);
$flag = false;
$Shop_Controller_Show->shopItems()->queryBuilder()
->open();
$ch = 0;
if(isset($condishion) and $condishion > 0 ) {
$Shop_Controller_Show->shopItems()->queryBuilder()
// Идентификатор дополнительного свойства
->where('shop_item_properties.property_id', '=', 72)
// Значание дополнительного свойства
->where('property_value_ints.value', '=', $condishion);
$ch++;
}
if(isset($city) and $city > 0 ) {
$Shop_Controller_Show->shopItems()->queryBuilder()
// Идентификатор дополнительного свойства
->where('shop_item_properties.property_id', '=', 95)
// Значание дополнительного свойства
->where('property_value_ints.value', '=', $city);
$ch++;
}
if($photo) {
$Shop_Controller_Show->shopItems()->queryBuilder()
// Идентификатор дополнительного свойства
->where('shop_item_properties.property_id', '=', 84)
// Значание дополнительного свойства
->where('property_value_files.file', '!=', '');
$ch++;
}
if(isset($year_start) and $year_start > 0 and isset($year_end) and $year_end > 0 ) {
$Shop_Controller_Show->shopItems()->queryBuilder()
// Идентификатор дополнительного свойства
->where('shop_item_properties.property_id', '=', 66)
// Значание дополнительного свойства
->where('property_value_ints.value', '>=', $year_start)
->where('property_value_ints.value', '<=', $year_end);
$ch++;
}
$Shop_Controller_Show->shopItems()->queryBuilder()->close();
if(isset($price) and $price > 0 ) {
// Получаем список валют магазина
$aShop_Currencies = Core_Entity::factory('Shop_Currency')->findAll();
$query_currency_switch = 'price';
$oShop = $Shop_Controller_Show->getEntity();
foreach ($aShop_Currencies as $oShop_Currency)
{
// Получаем коэффициент пересчета для каждой валюты
$currency_coefficient = Shop_Controller::instance()->getCurrencyCoefficientInShopCurrency(
$oShop_Currency, $oShop->Shop_Currency
);
$query_currency_switch = "IF (`shop_items`.`shop_currency_id` = '{$oShop_Currency->id}', IF (shop_discounts.percent, price * (100 - shop_discounts.percent) * {$currency_coefficient} / 100, shop_items.price * {$currency_coefficient}), {$query_currency_switch})";
}
$current_date = date('Y-m-d H:i:s');
$Shop_Controller_Show->shopItems()
->queryBuilder()
->select(array(Core_QueryBuilder::expression($query_currency_switch), 'absolute_price'))
->leftJoin('shop_item_discounts', 'shop_items.id', '=', 'shop_item_discounts.id')
->leftJoin('shop_discounts', 'shop_item_discounts.id', '=', 'shop_discounts.id', array(
array('AND (' => array('shop_discounts.end_datetime', '>=', $current_date)),
array('OR' => array('shop_discounts.end_datetime', '=', '0000-00-00 00:00:00')),
array('AND' => array('shop_discounts.start_datetime', '<=', $current_date)),
array(')' => NULL)
));
$Shop_Controller_Show->shopItems()->queryBuilder()->having('absolute_price', '<=', $price);
$Shop_Controller_Show->addEntity(
Core::factory('Core_Xml_Entity')
->name('price_to')->value($price)
);
$Shop_Controller_Show->shopItems()->queryBuilder()
->clearOrderBy()
->orderBy('absolute_price', 'ASC');
}
$Shop_Controller_Show->shopItems()->queryBuilder()->groupBy('shop_items.id')->having('COUNT(shop_item_properties.id)', '=', $ch);
$Shop_Controller_Show->shopItems()->queryBuilder()->where('shop_items.shop_group_id', 'IN', $neededGroups);
$Shop_Controller_Show->show();