Display product available sizes on product miniature Prestashop 1.7 - task-parallel-library

I would like to know how to show available product sizes on product miniature in Prestashop 1.7.
Variable $product.size gives an array so I tried somehow to use
<ul>
{foreach from=$product key=?? item=??}
<li>{$product.size}</li>
{/foreach}
</ul>
but doesn't work. Exactly it returns maybe 20 empty
file is located in your_theme/templates/catalog/_partials/miniatures/product.tpl
Could somebody help me?
Thanks is advance

Unfortunately in 1.7 you can't just display all attributes related to product, without additional modifications. By default, you have only access to "default" attribute.
There are number of additional modules to do that, you can search them by looking for "PrestaShop Attributes on product list" on both official and third party marketplaces.
If you want to consider doing modification by your own, I suggest to look at the Product::getProductsProperties method where you have a code which is used to get all informations about the product displayed on the list.

Display defaut attributes on product miniature Prestashop 1.7
file located : your_theme/templates/catalog/_partials/miniatures/product.tpl
{*------Display default attributes in product list-----*}
{if isset($product.attributes) && !empty($product.attributes)}
<span class="default-attributes">
{foreach from=$product.attributes item=attribute}
{$attribute.group} : {$attribute.name}
{/if}
{/foreach}
</span>
{/if}

For me works the solution by Idriss el basrii thanks to him
but you just delete the {/if} closure tag inside foreach :
{*------Display default attributes in product list-----*}
{if isset($product.attributes) && !empty($product.attributes)}
<span class="default-attributes">
{foreach from=$product.attributes item=attribute}
{$attribute.group} : {$attribute.name}
{/foreach}
</span>

Related

Possible to display available sizes in the product tile in Shoper

Is possible to show for example all available size in product tile? I use variant product with magazine support. Product without magazine support show on main page, category page in suitable product tile information about available size but product with magazine support show all size, also not available. I can't get any info about stock variant product, which allow me remove unnecessary info. product tile
First product is variant with magazine support, size 46 is not available (stock 0)
Second - product without magazine support
I have to be able to manage for example stock product variant because using magazine support
{assign var=options value=$product->getOptionsConfigurationStruct()}
{if $product->product->group_id && count($options)}
<div class="size-values-product">
{foreach from=$options item=option}
{if ($option.name|escape == 'Rozmiar')}
{foreach from=$option.values item=value}
<span value="{$value.id|escape}">{$value.name|escape}</span>
{/foreach}
{/if}
{/foreach}
</div>
{/if}
How do I do that?

Shopware rich-snippets add to products problem

I using Shopware 5.5.10 on my shop. I try to set "priceValidUntil" for each product for google search console because warning on it.
shopware told in version 5.5.8 update
Added rich-snippets for priceValidUntil , url, image and
gtin13
I have folloowing part in details/index.tpl
{block name='frontend_detail_index_buy_container_inner'}
<div itemprop="offers" itemscope itemtype="{if $sArticle.sBlockPrices}http://schema.org/AggregateOffer{else}http://schema.org/Offer{/if}" class="buybox--inner">
{* Product name *}
{block name='frontend_detail_index_name'}
<h1 class="product--title" itemprop="name" style="margin: 0px 0px 20px 0px; margin: 0rem 0rem 1.25rem 0rem;">
{$sArticle.articleName}
</h1>
{/block}
How I can add the 'priceValidUntil' rich-snippets to my products?
Shopware does not have a function that allows you to configure time-controlled prices. Accordingly there is only one template block where plugins that offer this functionality can add their rich snippets. Since the snippet is only recommended in cases where the price will be discontinued after a certain time.
This is the block: https://github.com/shopware/shopware/blob/8b4a754307c24cb26630ee72559b15b337e7ceff/themes/Frontend/Bare/frontend/detail/content/buy_container.tpl#L84
You can add your own data like this:
{extends file="parent:frontend/detail/content/buy_container.tpl"}
{block name="frontend_detail_index_data_price_valid_until"}
{$smarty.block.parent}
<meta itemprop="priceValidUntil" content="your-time" />
{/block}
Those are simple template adjustments that are described in the template tutorial of shopware. It is not recommended on normal prices, since they won't end at a certain time.
//EDIT:
https://github.com/shopware/shopware/blob/fe95215f7bb9da24f4b78a86300579b340f4a1c2/themes/Frontend/Bare/frontend/detail/content/header.tpl#L14
On the product detail page shopware will use the first image of the product automatically. There are not adjustments needed - if you want to change this behavior you can use the syntax like before and change the block you want to overwrite.
https://github.com/shopware/shopware/blob/fe95215f7bb9da24f4b78a86300579b340f4a1c2/themes/Frontend/Bare/frontend/detail/content/header.tpl#L20
The same thing with ean. Shopware will use the Ean field as gtin and check the length of the input. You can use simple template adjustments to overwrite this logic.
https://github.com/shopware/shopware/blob/96161effd05153d4b95f4a9324998c047988724c/themes/Frontend/Bare/frontend/_includes/rating.tpl#L77
And the same with rating too.

Smarty target last item

So after using cscart for a while now and learning everyday I have encountered something which I find rather annoying.
So whenever you add multiple values to a feature it will show them like f.e. "OrangeGreen" whilst I want it to view it like "Orange, Green". Well seems easy, just change the product_features.tpl
{elseif in_array($feature.feature_type, ["ProductFeatures::TEXT_SELECTBOX"|enum, "ProductFeatures::EXTENDED"|enum, "ProductFeatures::NUMBER_SELECTBOX"|enum])}
{foreach from=$feature.variants item="var"}
{if $var.selected}{$var.variant}, {/if}
{/foreach}
But now it won't be "Orange, Green". Now it is "Orange, Green,"
So could you guys help me and figure out how I can target the last item in this piece of code?
You can use foreach loop's properties like index, first and last to access particular elements in this loop.
In Smarty V2 your foreach loop needs a name attribute for accessing it's properties:
{foreach from=$feature.variants item="var" name="features"}
{if $var.selected}{$var.variant}, {/if}
{if $smarty.foreach.features.last} this is the last element in this loop{/if}
{/foreach}
(docs: http://www.smarty.net/docsv2/en/language.function.foreach.tpl#foreach.property.last)
Smarty V3 is even simplier:
{if $var#last} this is the last element in this loop{/if}
(docs: http://www.smarty.net/docs/en/language.function.foreach.tpl#foreach.property.last )
sorry, i'm not sure if cs-cart works with Smarty V2 or V3

Display attribute image instead of text

I figure out how to show attribute in category of product list, what I need is to display an image instead of text.
Eg. I have an attribute text ASUS and a image located in media/brands/ named asus.gif or instead of Western-Digital display image located in media/brands/western-digital.gif.
I hope you understand
What you want to do is
<img src="<?php echo $this->getMediaUrl(); ?>brands/<?php echo strtolower($_product->getManufacturer()); ?>.png" />
getManufacturer may be the attribte, change it, if needed.
I found the solution:
<?php $brand=$_product->getAttributeText('manufacturer');
echo '<img style="float: right; margin: 2px;" src="/media/catalog/brands/'.str_replace(' ', '_',$brand).'.gif" alt="'.$brand.'">' ?>
If your attribute is a dropdown one you could add a new column in the table eav_attribute_option_value and in the "manage options/labels" tab of the manage attribute page in the admin panel. For each option values, next to each store traduction, you could store the name of your image and retrieve it in your templates.. it require some development but it's doable and easy to administrate.
Or the quick and dirty way : use the admin label string, lowercase it and clean to retrieve an image related filename
In the Magento 1.7.0.2 you can accomplish this in a very easy way...
All you do is create a new attribute, and select 'media image' from the 'catalog input type..' dropdown.

How to retrieve Categories name and children ? Magento

I would like to retrieve the categories of my website in order to build me own Category menu.
but I don't understand how to get all the categories from the class/model. So I've created a file called top.phtml that I've put in template/catalog/navigation ,
First, do I MUST put that name to the file into that folder if I want to create a top Menu ? Can t I decide where to put it with the name I want like TopMenu.phtml ? Because in evry tut I red, they are doing the same way ..
Second : What i the function I must call ? I've been here : http://www.magentix.fr/ergonomie-web/agencer-page-accueil-site-magento.html but the way the do that doesn t work for me .. I add that code to my file top.phtml properly called in the page.xml :
<div class="category-list" style="background-color:white;">
<h2>Nos produits</h2>
<?php
foreach ($this->getStoreCategories() as $_category):
if($_category->getIsActive()):
$_category = Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer')->setCurrentCategory($_category);
?>
<div class="category-list-view">
<a href="<?php echo $this->getCategoryUrl($_category)?>" title="<?php echo $_category->getName()?>">
<img src="<?php echo $this->getCurrentCategory()->getImageUrl(); ?>" alt="<?php echo $_category->getName() ?>" />
</a>
<h3><?php echo $_category->getName()?></h3>
</div>
<?php
endif;
endforeach;
?>
</div>
Last : where could I find a clear user guide like there is for CodeIgniter ? I found that, but I never found any answer on it : http://www.magentocommerce.com/wiki/doc/webservices-api/api#magento_core_api
Thanks for your answers, I m a web dev used to work with CodeIgniter or without any template, and I can t clearly see the logic behind Magento way of programming.
EDIT: Is there anything to do with the categories ? Becaue I tried to create a sub category under the Default Category and it do work, but if I create a new Root Category,It simply didnt recognize it .. why
First, do I MUST put that name to the file into that folder if I want to create a top Menu ? Can t I decide where to put it with the name I want like TopMenu.phtml ? Because in evry tut I red, they are doing the same way ..
You can name your template file whatever you like. However, it's best to follow the nomenclature and established conventions. The template filename is contingent on your layout XML. It should have the template attribute, something like <block name="x" type="x/y" template="catalog/navigation/topmenu.phtml" /> (for example).
Second : What i the function I must call ? I've been here : http://www.magentix.fr/ergonomie-web/agencer-page-accueil-site-magento.html but the way the do that doesn t work for me
The functions available to your template (topmenu.phtml file) depend on the block's type. In your layout XML, you should specify the block type that corresponds to the functionality you need. In your case, you're probably looking for the block type to be catalog/navigation. If you look in ./app/code/core/Mage/Catalog/Block/Navigation.php, you can see what public methods are available to your template. Several of the methods here facilitate generating (nested) category listing. This is where your getStoreCategories() method comes from. Remember that these blocks inherit from several parenting classes, so you have a lot more methods available than you may at first think.
where could I find a clear user guide like there is for CodeIgniter ? I found that, but I never found any answer on it : http://www.magentocommerce.com/wiki/doc/webservices-api/api#magento_core_api
That's a link to the Magento API. What you need is a tutorial on Magento layout XML and the design layer therein. The Magento wiki has some good info, but Google around and you'll find a ton of really helpful resources on understanding Magento's design system.
Is there anything to do with the categories ? Becaue I tried to create a sub category under the Default Category and it do work, but if I create a new Root Category,It simply didnt recognize it .. why
A root category is what you'll use to identify the basis of the catalog for the selected store(s). You will never see the root category appear on the frontend (and you shouldn't). Each subcategory within the root category is the top-level category; sub-categories beneath those subcategories (tertiary categories) would appear as your "second-level" categories on the Magento frontend. You might want to look into Magento's GWS ("global, website, store") scope system, and how it manages catalog data in a multi-store setup to better understand why root categories function this way.
Hope this helps!

Resources