Jump to content

Show color texture picture in shopping cart


matthieu

Recommended Posts

Hello,

I try to add product color texture picture on shopping-cart.
But this information is not available on cart product object.
The only informations are attributes in plan text, for example :
Couleur : Vert, XS : M

I can display the picture by adding colors attributes in Cart class :

$product = new Product($row['id_product']);
$colors = array();
$attributesGroups = $product->getAttributesGroups(intval($cookie->id_lang));

if (Db::getInstance()->numRows())
{
   $combinationImages = $product->getCombinationImages(intval($cookie->id_lang));
   foreach ($attributesGroups AS $k => $row3)
   {
       /* Color management */
       if (isset($row3['attribute_color']) AND $row3['attribute_color'] AND $row3['id_attribute_group'] == $product->id_color_default)
       {
           $colors[$row3['id_attribute']]['value'] = $row3['attribute_color'];
           $colors[$row3['id_attribute']]['name'] = $row3['attribute_name'];
       }
   }
}
$row['colors']=$colors;



So I have the picture from $colors.
But I have attribute value too (Couleur : Vert).

So I update attributes query in Cart class by adding a condition in WHERE clause :

$result2 = Db::getInstance()->ExecuteS('
               SELECT agl.`public_name` AS public_group_name, al.`name` AS attribute_name
               FROM `'._DB_PREFIX_.'product_attribute_combination` pac
               LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute`
               LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
               LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.intval($this->id_lang).')
               LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.intval($this->id_lang).')
               WHERE pac.`id_product_attribute` = '.intval($row['id_product_attribute']).' AND ag.is_color_group!=1');



Is there a better way to do that ?
Because I'm not sure it's properly done.

Thanks

Link to comment
Share on other sites

  • 9 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...