Jump to content

Extend Product Object with old shop product ID


PoOwAa

Recommended Posts

Dear Community,

 

I would like to extend (override) products in PrestaShop 1.6.1.5. We are on several marketplaces long time ago, and some of them asking unique ID for each product. We used in our old shop (based on Joomla) the product ID as unique ID. In PrestaShop the ID changed. I would like to implement these ID into product object.

 

Firstly I started to override the productCore object:

  /** 
   * @var int Old shop (joomla) product ID
   */
  public $joomla_id;

  public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
  {
    self::$definition['fields']['joomla_id'] = array('type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isInt');
    parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
  }

I just added a new column (joomla_id) into these tables: ps_product, ps_product_shop.

 

We're using multishops and product attributes. I would like to extend ps_product_attribute too, because in the old shop the attributes were single products, so they have different ID than the main product of attribute.

 

Which class/classes should I ovverride, and where should I add extra columns?

 

I would like to use in my own modules something like this:

 

$p = new Product($id);

$joomlaId = $p->joomla_id;

 

Same with product attributes.

 

Thanks in advance!

Best Regards,

 

Raymund

Edited by PoOwAa (see edit history)
Link to comment
Share on other sites

Noone answered, so I did my own workaround.

 

Firstly I just copied the IDs into ps_product and ps_product_attribute table:

UPDATE ps_product pp
LEFT JOIN jos_vm_product jp ON pp.reference = jp.product_sku
SET pp.joomla_id = IF(jp.product_id > 0, jp.product_id, pp.id_product);

UPDATE ps_product_attribute ppa
LEFT JOIN jos_vm_product jp ON ppa.reference = jp.product_sku
SET ppa.joomla_id = IF(jp.product_id > 0, jp.product_id, ppa.id_product_attribute);

After that just extended the definitons like this:

<?php
/**
 * Extend product attributes with old shop (Joomla) product ID
 * 
 * @author Ács Raymund <[email protected]>
 * @date 2017.10.17.
 * @version 0.1
 */


class Attribute extends AttributeCore {
    /** 
     * @var int Old Shop (joomla) product ID
     */
    public $joomla_id;


    public function __construct($id = null, $id_lang = null, $id_shop = null)
    {
        /**
         * Just add the new field into definitions ObjectModel class will do the magic
         */
        self::$definition['fields']['joomla_id'] = array('type' => self::TYPE_INT, 'validate' => 'isInt');
        
        /**
         * AttributeCore __construct
         */
        $this->image_dir = _PS_COL_IMG_DIR_;
        parent::__construct($id, $id_lang, $id_shop);
    }
}
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...