Jump to content

Create Alias for product


treyj45

Recommended Posts

Hi,

Is there a way to create a prdouct alias?  Basically I want to have the same product have two names for sorting purposes when displayed in the category.  The customer could logically look two places for the product in a list.  I dont want to make a new product because they are the same thing, just with a slight modification to the name. Can one product somehow be a dummy name to refer back to the other one?    Thanks

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

Prestashop used to have fields where you could define what happens when a page is no longer present. These are the database fields redirect_type and id_product_redirected in the ps_product_shop table.

 

They are still there. However, they are no longer in the backoffice and it looks like their support has totally disappeared as they can't be found in the source code anymore.

Link to comment
Share on other sites

Thanks, that got me thinking.  I figured it out.  It might not be the prettiest, but it works for me.

 

 

Then I created a new product with only the title I want(the alias) and the original product it is referencing .  I created a new field in the ps_product table named alias_master_id and default value of 0.  I just made an admin field to change it, and then I just put the original master ID inside of this field. 

 

Then I overwrote the category class in the function getProducts I changed this code

return Product::getProductsProperties($id_lang, $result);

To :

 $displayed_products = Product::getProductsProperties($id_lang, $result);
        foreach ($displayed_products as $key => $alias) {
            if ($alias['alias_master_id'] != 0) {

                //Assign master vars              
                $master_product = new Product($alias['alias_master_id'], true, Configuration::get('PS_LANG_DEFAULT'));
                $master_product_vars = get_object_vars($master_product);
                $master_product_vars['id_product'] = $alias['alias_master_id'];

                //Assign propertiy vars for master product
                $product = Product::getProductProperties($id_lang, $master_product_vars);

                //Overwrite name with alias name
                $product['name'] = $alias['name'];

                //Get default image
                $image_array= $master_product->getCombinationImages($id_lang);
                $product['id_image'] = $master_product_vars['id_product'] .'-'. $image_array[$master_product_vars['cache_default_attribute']][0]['id_image'];
  
                //Update main array
                $displayed_products[$key] = $product;
   
            }

           
        }

        return $displayed_products;

It seems to be working how I would want it to.

Edited by treyj45 (see edit history)
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...