Jump to content

Exporting product-combinations Google Merchant Center


remyessers

Recommended Posts

Hi,

 

I'm using the Google Merchant Center module, bought from the addons store. This module exports all my products to an XML feed, which I'm using for google shopping and a few affiliate programs.

 

This module has the option to export a product with attributes to several products, based on the number of attributes.

 

In my furniture shop I combine multiple color chairs with these attributes and I'm able to export them as seperate products, which is great. But there's one limitation: I don't want to generate seperate products from the attributes "sizes", "color base", "material", because I get thousands of seperate products in my product feed.

 

In the php code, this is the function (I guess) which fetches the product attributes:

public function getProductAttributes($id_product, $id_attribute_group, $id_lang, $id_product_attribute = false)
{
 $result = Db::getInstance()->ExecuteS('SELECT distinct(al.`name`)
 FROM `'._DB_PREFIX_.'product_attribute` pa
 '.(version_compare(_PS_VERSION_, '1.5', '>') ? Shop::addSqlAssociation('product_attribute', 'pa', false) : '').'
 LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
 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`
 WHERE pa.`id_product` = '.(int)($id_product).
 (($id_product_attribute) ? ' AND pac.`id_product_attribute` = '.(int)($id_product_attribute) : '').'
 AND al.`id_lang` = '.(int)($id_lang).'
 AND ag.`id_attribute_group` = '.(int)($id_attribute_group).'
 ORDER BY al.`name` LIMIT 0, 10');
 if ($result)
  return $result;

 return false;
}

 

I only want this function to get the attributes from id_attribute_group "16". How do I change this code, can anyone point me in the right direction?

 

Thanks for your help!

Link to comment
Share on other sites

Not sure but probably most easy way is check $id_attribute_group to value 16 before execute sql query.

So something like this.

 

public function getProductAttributes($id_product, $id_attribute_group, $id_lang, $id_product_attribute = false)

{

if ($id_attribute_group != 16) {

return false;

}

 

...

Link to comment
Share on other sites

Not sure but probably most easy way is check $id_attribute_group to value 16 before execute sql query.

So something like this.

 

public function getProductAttributes($id_product, $id_attribute_group, $id_lang, $id_product_attribute = false)

{

if ($id_attribute_group != 16) {

return false;

}

 

...

 

Ok, I tried it, but it's not working. There are a few functions related to the getattributes function, see the code below:

public function getProductAttributes($id_product, $id_attribute_group, $id_lang, $id_product_attribute = false)
{
 $result = Db::getInstance()->ExecuteS('SELECT distinct(al.`name`)
 FROM `'._DB_PREFIX_.'product_attribute` pa
 '.(version_compare(_PS_VERSION_, '1.5', '>') ? Shop::addSqlAssociation('product_attribute', 'pa', false) : '').'
 LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
 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`
 WHERE pa.`id_product` = '.(int)($id_product).
 (($id_product_attribute) ? ' AND pac.`id_product_attribute` = '.(int)($id_product_attribute) : '').'
 AND al.`id_lang` = '.(int)($id_lang).'
 AND ag.`id_attribute_group` = '.(int)($id_attribute_group).'
 ORDER BY al.`name` LIMIT 0, 10');
 if ($result)
  return $result;

 return false;
}
/* Get product attribute combinations for a given product */

public function getProductCombos($id_product)
{
 if (version_compare(_PS_VERSION_, '1.5', '>'))
 {

  $result = Db::getInstance()->ExecuteS('SELECT *, sa.`quantity` as combo_quantity
  FROM `'._DB_PREFIX_.'product_attribute` pa
  LEFT JOIN`'._DB_PREFIX_.'product_attribute_shop` pas ON (pa.id_product_attribute = pas.id_product_attribute)
  LEFT JOIN `'._DB_PREFIX_.'stock_available` sa ON (pas.id_product_attribute = sa.id_product_attribute AND pas.id_shop = sa.id_shop AND pas.id_shop = '.(int)($this->id_shop).')
  WHERE pa.`id_product` = '.(int)($id_product));
 }

 else
 {
  $result = Db::getInstance()->ExecuteS('SELECT *, `quantity` as combo_quantity
  FROM `'._DB_PREFIX_.'product_attribute`
  WHERE `id_product` = '.(int)($id_product));
 }

 if ($result)
  return $result;
 return false;
}

/* Get attributes for a given product attribute combination */
public function getProductComboAttributes($id_product_attribute, $id_lang)
{
 if (version_compare(_PS_VERSION_, '1.5', '>'))
 {
  $result = Db::getInstance()->ExecuteS('SELECT distinct(al.`name`)
  FROM `'._DB_PREFIX_.'product_attribute_shop` pa
  LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
  LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON pac.`id_attribute` = al.`id_attribute`
  WHERE pac.`id_product_attribute` = '.(int)($id_product_attribute).'
  AND al.`id_lang` = '.(int)($id_lang).'
  AND pa.id_shop = '.(int)($this->id_shop).'
  ORDER BY al.`name`');
 }
 else
 {
  $result = Db::getInstance()->ExecuteS('SELECT distinct(al.`name`)
  FROM `'._DB_PREFIX_.'product_attribute` pa
  LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
  LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON pac.`id_attribute` = al.`id_attribute`
  WHERE pac.`id_product_attribute` = '.(int)($id_product_attribute).'
  AND al.`id_lang` = '.(int)($id_lang).'
  ORDER BY al.`name`');
 }
 if ($result)
  return $result;

 return true;
}

 

Perhaps I have to add it somewhere else? I really appreciate you looking at it! Thanks!

Link to comment
Share on other sites

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...