Short version : I want to get product photos that are assigned to product's attribute groups.
Long version : I want to accomplish the feature by
creating a custom module : on product page, you can choose a product
color by choosing from a list of product's photos representing different
colors, just like here : http://www.kupbuty.com/product-pol-6941-Komin-wzor-w-koleczka-SZ-MRA-110-Granat.html
(sorry that it's polish, but I think you'll get the idea). I've already
accomplished to get the attributes groups of a product with distinct
colours by using the code below (I get all attribute groups and if I
haven't got a group with a given color name already then I add it to
array $colors):
$attr=$product->getAttributesGroups($this->context->language->id);
$colors=array();
$exists=array();
foreach ($attr as $key => $a) {
if($a['id_attribute_group']==Configuration::get($this->name.'_attr_id'))
{
if(!in_array($a['attribute_name'], $exists))
{
$colors[]=$a;
$exists[]=$a['attribute_name'];
}
}
}
Now I looked into Product class and I can't understand how I can get
images associated with selected product groups. I've also printed whole
$colors content, but I did not see any relevant fields.
The images are correctly assigned to attributs combinations in the
admin. Can you point me in some direction?
EDIT : To make myself more clear - I want to get PRODUCT'S PHOTO
assigned to specific attribute value - let's say I have shoes that can
be black or white, I want to get white shoe image and black shoe image.
The attributes are organized in combinations (I think it's now called
"groups"?) of color and size, and every combination has a set of photos -
I want to access this photos list.
Answer:
You won't find anything useful into the Product class because the
attribute-image association done on Prestashop for Attributes value is
done in a silly and simply way.
when you save an image associated to an attribute, a image file is
created under the specific folder
so for example if you want to check the image for the id_attribute 5, you will find it under:
By working that way you will see that both in admin and on the frontend each time the attributes' images have to be shown the code is directly placed in the template, without any preprocessing involved on the Controller/Class.
for example in the product page, the product.tpl has something along the line of:
_THEME_COL_DIR_that is nothing more than the "co" subfolder under the prestashop image directory, with the id_attribute as namefile and jpg as file extension.
so for example if you want to check the image for the id_attribute 5, you will find it under:
_THEME_COL_DIR.$id_attribute.'jpg' => '/img/co/5.jpg';By working that way you will see that both in admin and on the frontend each time the attributes' images have to be shown the code is directly placed in the template, without any preprocessing involved on the Controller/Class.
for example in the product page, the product.tpl has something along the line of:
<a id="color_{$id_attribute|intval}" class="color_pick{if ($group.default == $id_attribute)} selected{/if}" style="background: {$colors.$id_attribute.value};" title="{$colors.$id_attribute.name}" onclick="colorPickerClick(this);getProductAttribute();{if $colors|@count > 0}$('#wrapResetImages').show('slow');{/if}">
{if file_exists($col_img_dir|cat:$id_attribute|cat:'.jpg')}
<img src="{$img_col_dir}{$id_attribute}.jpg" alt="{$colors.$id_attribute.name}" width="20" height="20" /><br>
{/if} ... </a>
where both the image existance and the url are created directly in
the template by simply using the img_col_dir and the id_attribute
No comments:
Post a Comment