braincord Posted March 13, 2015 Posted March 13, 2015 Здравствуйте! Тут появилась необходимость вывести товар в карточке товара с той же моделью(характеристикой), что и сам товар в карточке. Надеюсь понятно написал задачку. Что я сделал: Создал характеристику товара, заполнил ее и привязал к каждому товару, после этого приступил к выводу ее В ProductController.php добавил: 'productmodel' => $this->product->getProdModel($this->context->language->id), после строки: 'accessories' => $this->product->getAccessories($this->context->language->id), После этого в Product.php добавил следующий код: /** * Get product getProdModel * * @param integer $id_lang Language id * @return array Product getProdModel */ public function getProdModel($id_lang, $active = true, Context $context = null) { $sqlpm = 'SELECT p.*, fv.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, pl.`available_now`, pl.`available_later`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` as manufacturer_name, cl.`name` AS category_default, DATEDIFF( p.`date_add`, DATE_SUB( NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY ) ) > 0 AS new FROM `'._DB_PREFIX_.'feature_produt` LEFT JOIN `'._DB_PREFIX_.'feature_value_lang` fv ON fv.`id_feature_value` = `id_feature_value` '.Shop::addSqlAssociation('feature_value_lang', 'fv').' LEFT JOIN `'._DB_PREFIX_.'feature_value` f ON f.`id_feature` = `id_feature` '.Shop::addSqlAssociation('feature_value', 'f').' LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = `id_product` '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON ( p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' ) LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ( product_shop.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').' ) LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (p.`id_manufacturer`= m.`id_manufacturer`) '.Product::sqlStock('p', 0).' WHERE `id_feature` = "14" AND `id_feature_value` = ( SELECT `id_feature_value` FROM `'._DB_PREFIX_.'feature_value_lang` LEFT JOIN `'._DB_PREFIX_.'feature_produt` fp2 ON fp2.`id_feature_value` = `id_feature_value` WHERE fp2.`id_product` = '.(int)$this->id. ($active ? ' AND product_shop.`active` = 1 AND product_shop.`visibility` != \'none\'' : '').' GROUP BY product_shop.id_product'; if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sqlpm)) return false; foreach ($result as &$row) $row['id_product_attribute'] = Product::getDefaultAttribute((int)$row['id_product']); return $this->getProductsProperties($id_lang, $result); } Ну и в самом шаблоне карточки товара добавил следующий код product.tpl: <!--productmodel --> <section class="page-product-box"> <h3 class="page-product-heading">{l s='Запчасти:'}</h3> <div class="block products_block accessories-block clearfix"> <div class="block_content"> <div class="block_content"> {foreach from=$productmodel item=productmodels name=productmodel_list} {if ($productmodels.allow_oosp || $productmodels.quantity_all_versions > 0 || $productmodels.quantity > 0) && $productmodels.available_for_order && !isset($restricted_country_mode)} {assign var='productmodelsLink' value=$link->getProductLink($productmodels.id_product, $productmodels.link_rewrite, $productmodels.category)} <p> <div class="s_title_block"> <h5 class="product-name"> <a href="{$productmodelsLink|escape:'html':'UTF-8'}"> {$productmodels.name|truncate:100:'...':true|escape:'html':'UTF-8'} </a> </h5> {if $productmodels.show_price && !isset($restricted_country_mode) && !$PS_CATALOG_MODE} <span class="price"> {if $priceDisplay != 1} {displayWtPrice p=$productmodels.price}{else}{displayWtPrice p=$productmodels.price_tax_exc} {/if} </span> {/if} </div> <div class="clearfix" style="margin-top:5px"> {if !$PS_CATALOG_MODE && ($productmodels.allow_oosp || $productmodels.quantity > 0)} <div class="no-print"> <a class="exclusive button ajax_add_to_cart_button" href="{$link->getPageLink('cart', true, NULL, "qty=1&id_product={$productmodels.id_product|intval}&token={$static_token}&add")|escape:'html':'UTF-8'}" data-id-product="{$productmodels.id_product|intval}" title="{l s='Add to cart'}"> <span>{l s='В корзину'}</span> </a> </div> {/if} </div> </p> {/if} {/foreach} </div> </div> </div> </section> <!--end Accessories --> Но результат пустой Не могу понять что я делаю нет, профи помогит плиз. Share this post Link to post Share on other sites More sharing options...
braincord Posted March 14, 2015 Posted March 14, 2015 Вот переписал SQL запрос: Пока переписал SQL запрос: Код: SELECT a.id_product, a.id_manufacturer, a.id_category_default, a.price, al.name, al.link_rewrite, fvl.value FROM vr_product a INNER JOIN vr_product_lang al ON a.id_product=al.id_product INNER JOIN vr_feature_product fp ON a.id_product=fp.id_product INNER JOIN vr_feature_value_lang fvl ON fvl.id_feature_value=fp.id_feature_value INNER JOIN vr_feature_value fv ON fv.id_feature_value=fvl.id_feature_value WHERE fv.id_feature='14' AND fvl.value IN ( SELECT fvl2.value FROM vr_feature_value_lang fvl2 INNER JOIN vr_feature_product fp2 ON fvl2.id_feature_value=fp2.id_feature_value WHERE fp2.id_product='157') Можете подставить свои значения и посмотреть то что я хотел получить. Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now