paplo22 Posted March 10, 2017 Share Posted March 10, 2017 (edited) Witam gdzie w 'controllers' albo coś innego muszę dopisać żebym mógł w pliku: 'product-list.tpl' dopisać coś typu: {foreach from=$groups key=id_attribute_group item=group} {foreach from=$group.attributes key=id_attribute item=group_attribute} <p>{$group_attribute|escape:'html':'UTF-8'}</p> {/foreach} {/foreach} ponieważ w kategoriach chciałbym mieć np nad nazwą produktu dostępne rozmiary? Edited March 10, 2017 by paplo22 (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted March 10, 2017 Share Posted March 10, 2017 przedstawiony kod jest kodem smarty i nie może być umieszczony w kontrolerach (w kontrolerach umieszczamy tylko kod php). ponieważ w kategoriach chciałbym mieć np nad nazwą produktu dostępne rozmiary? umieszczamy kod nad fragmentem <h5 itemprop="name"> {if isset($product.pack_quantity) && $product.pack_quantity}{$product.pack_quantity|intval|cat:' x '}{/if} <a class="product-name" href="{$product.link|escape:'html':'UTF-8'}" title="{$product.name|escape:'html':'UTF-8'}" itemprop="url" > {$product.name|truncate:45:'...'|escape:'html':'UTF-8'} </a> </h5> obawiam sie, że kod nie będzie działał z uwagi na to, że zmienne takie jak $group nie są zdefiniowane, to raczej kompleksowe rowiązanie, zwykłe kopiuj wklej wspomnianego kodu nie wystarczy Link to comment Share on other sites More sharing options...
paplo22 Posted March 13, 2017 Author Share Posted March 13, 2017 (edited) Chyba trochę źle wytłumaczyłem, to jeszcze raz: To wiem już: product-list.tpl ...<div class="right-block"> <h5>Rozmiary: </h5> {assign var="pSize" value=Product::geSizeNameByID($product.id_product)} {foreach from=$pSize item=size name=sizes} <span id="rozmiar_{$smarty.foreach.sizes.index}">{$size}</span> {/foreach} <h5 itemprop="name"> {if isset($product.pack_quantity) && $product.pack_quantity}{$product.pack_quantity|intval|cat:' x '}{/if} <a class="product-name" href="{$product.link|escape:'html':'UTF-8'}" title="{$product.name|escape:'html':'UTF-8'}" itemprop="url" > {$product.name|truncate:45:'...'|escape:'html':'UTF-8'} </a> </h5>... class/Product.php: public static function geSizeNameByID($id_product){ $id_att = Db::getInstance()->ExecuteS(' JAKIE TUTAJ ZAPYTANIE?? `id_product` = '.(int)($id_product)); $toReturn = array(); if(!$id_att) $toReturn[] = "uni"; else foreach($id_att as $size) $toReturn[] = $size['name']; return $toReturn; } Do tego doszedłem... ale teraz próbuję zrobić jakieś zapytanie SQL. Próbuje ale już się chyba poddaje... nie wiem jak polaczyć te tabele: `ps_attribute_impact` `ps_attribute_lang` `ps_product_attribute` `ps_stock_available` Nie ma tam nic wspólnego po czym mógłbym to połączyć? Proszę o jakaś podpowiedz? może zapomniałem o jakieś tabeli? czy w ogólę da się to zrobić tylko po `id_product`? narazi mam tyle: SELECT `ps_attribute_lang`.`name` FROM ps_attribute_impact LEFT JOIN ps_attribute_lang USING (`id_attribute`) WHERE `ps_attribute_lang`.`id_lang` = 1 AND `ps_attribute_impact`.`id_product` = 1698 tylko nie umiem dodać żeby pojawiły się tylko te które maja ilość większą niż 0 P.S bo nie wiem ale w attribute_impact? na pewno są wszystkie atrybuty dla każdego produktu? bo nie wszystkie mi się pojawiają? a w administratorze maja kombinacje.. i już się pogubiłem Edited March 13, 2017 by paplo22 (see edit history) Link to comment Share on other sites More sharing options...
paplo22 Posted March 13, 2017 Author Share Posted March 13, 2017 Rozwiązane jak by ktoś chciał: class/Product.php: public static function getProductAttributeCombinations($id_product) { $combinations = array(); $context = Context::getContext(); $product = new Product ($id_product, $context->language->id); $attributes_groups = $product->getAttributesGroups($context->language->id); $att_grps = ''; foreach ($attributes_groups as $k => $row) { $combinations[$row['id_product_attribute']]['attributes_values'][$row['id_attribute_group']] = $row['attribute_name']; $combinations[$row['id_product_attribute']]['attributes_group'][$row['id_attribute_group']] = $row['group_name']; $combinations[$row['id_product_attribute']]['attributes_groups'] = @implode(', ', $combinations[$row['id_product_attribute']]['attributes_group']); $att_grps = $combinations[$row['id_product_attribute']]['attributes_groups']; $combinations[$row['id_product_attribute']]['attributes_names'] = @implode(', ', $combinations[$row['id_product_attribute']]['attributes_values']); $combinations[$row['id_product_attribute']]['attributes'][] = (int)$row['id_attribute']; $combinations[$row['id_product_attribute']]['price'] = (float)$row['price']; // Call getPriceStatic in order to set $combination_specific_price if (!isset($combination_prices_set[(int)$row['id_product_attribute']])) { Product::getPriceStatic((int)$product->id, false, $row['id_product_attribute'], 6, null, false, true, 1, false, null, null, null, $combination_specific_price); $combination_prices_set[(int)$row['id_product_attribute']] = true; $combinations[$row['id_product_attribute']]['specific_price'] = $combination_specific_price; } $combinations[$row['id_product_attribute']]['ecotax'] = (float)$row['ecotax']; $combinations[$row['id_product_attribute']]['weight'] = (float)$row['weight']; $combinations[$row['id_product_attribute']]['quantity'] = (int)$row['quantity']; $combinations[$row['id_product_attribute']]['reference'] = $row['reference']; $combinations[$row['id_product_attribute']]['unit_impact'] = $row['unit_price_impact']; $combinations[$row['id_product_attribute']]['minimal_quantity'] = $row['minimal_quantity']; if ($row['available_date'] != '0000-00-00') { $combinations[$row['id_product_attribute']]['available_date'] = $row['available_date']; $combinations[$row['id_product_attribute']]['date_formatted'] = Tools::displayDate($row['available_date']); } else $combinations[$row['id_product_attribute']]['available_date'] = ''; foreach ($combinations as $id_product_attribute => $comb) { $attribute_list = ''; foreach ($comb['attributes'] as $id_attribute) $attribute_list .= '\''.(int)$id_attribute.'\','; $attribute_list = rtrim($attribute_list, ','); $combinations[$id_product_attribute]['list'] = $attribute_list; } } $comb = array( 'attribute_groups' => $att_grps, 'values' => $combinations ); return $comb; } product-list.tpl: {assign var="pSize" value=Product::getProductAttributeCombinations($product.id_product)} <h5>Rozmiar:</h5> <div> {foreach from=$pSize.values item=size name=sizes} {if $size.quantity > 0} <div> <span>{$size.attributes_names|escape:'html':'UTF-8'}</span> </div> {/if} {/foreach} </div> CSS już wklejać nie będę. źródło: https://www.prestashop.com/forums/topic/279551-how-to-show-product-attribute-option-in-product-list/page-3 Link to comment 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