Jump to content

[Solved] Search by combinations Reference Number


Recommended Posts

Hello againnnn!

 

I have some products with combinations, and each combinations has it's own reference number.

When i try searching those reference numbers, it says "not found"

 

the easiest way was putting all the reference numbers on the main product.

 

product: reference1,reference2,reference3

 

and it worked fine for a few products, but when i add new products and use that same way for the reference numbers, it only finds search results with the 1st one....

 

So, my question is:

 

IS there a way for the search engine to search the combinations reference numbers?

Or, why is not working with , comas ?

 

Appreciate the help and the ideas! n.n

ty

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

... lol

i swear i had posted the solution o...... oh well

 

(me, using ps 1.4.7.0)

file to edit: classes/search.php

 

find: getAttributes function (around line 300)

 

replace with this:

 

 

public static function getAttributes($db, $id_product, $id_lang)
{
$attributes = '';
$attributesArray = $db->ExecuteS('
SELECT al.name, pa.reference FROM '._DB_PREFIX_.'product_attribute pa
INNER JOIN '._DB_PREFIX_.'product_attribute_combination pac ON pa.id_product_attribute = pac.id_product_attribute
INNER JOIN '._DB_PREFIX_.'attribute_lang al ON (pac.id_attribute = al.id_attribute AND al.id_lang = '.(int)$id_lang.')
WHERE pa.id_product = '.(int)$id_product);
foreach ($attributesArray AS $attribute)
$attributes .= $attribute['reference'].' ';
$attributes .= $attribute['reference'].' ';
return $attributes;
}

 

n.n there u go!

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

  • 4 weeks later...
  • 7 months later...
  • 3 years later...
  • 2 years later...
  • 4 months later...
  • 4 weeks later...

I want to share my solution for 1.7.4+

It is not the best, but it is working.

step 1) make an module.

You can generate a simple module here: https://validator.prestashop.com/generator . Don't rush to install it. It is the last step.

step 2write a hook in the module.

    public function hookActionAdminProductsListingFieldsModifier($list){
        
        if(isset($_POST['filter_column_reference']) && !empty($_POST['filter_column_reference'])){
            $query=$_POST['filter_column_reference'];
            $list['sql_where']=array('
                (
                EXISTS(SELECT * FROM `' . _DB_PREFIX_ . 'product_attribute` `pa` WHERE pa.`id_product` = p.`id_product` AND (pa.`reference` LIKE \'%' . pSQL($query) . '%\'
                OR pa.`supplier_reference` LIKE \'%' . pSQL($query) . '%\'
                OR pa.`ean13` LIKE \'%' . pSQL($query) . '%\'
                OR pa.`isbn` LIKE \'%' . pSQL($query) . '%\'
                OR pa.`upc` LIKE \'%' . pSQL($query) . '%\'))
                )

                OR

                p.`reference` LIKE \'%' . pSQL($query) . '%\'
                '
            );
        }
    }

 

step 3) register the hook.
Maybe the best way is to do it during install of the module.

    public function install()
    {
        if (!parent::install()
            || $this->registerHook('actionAdminProductsListingFieldsModifier')
        ) {
            return false;
        }
        $installer = InstallerFactory::create();
        return $installer->install($this);
    }

 

step 4) Install the module.

The idea to install the module you've just created and modified last is to register the hook.

If everything went OK you'll be able to search by reference all combinations in the back office /administration/ .


NB! Make sure the hook is registered.

Check out the DB tables: ps_hook , ps_hook_module

ps_hook should contain row with name = actionAdminProductsListingFieldsModifier

ps_hook_module should contain the ID of the hook from ps_hook, and the ID of the module you've created (it should appear in ps_hook_module).

 

  • Like 1
Link to comment
Share on other sites

I have Prestashop 1.7.6 and this featured is alredy working with no modules at front and back office( am using a custom theme).

The thing nobody have solved yet is:

A Product was created with reference C7285-M (main product before combinations).

Then combinations were created:
 -C7825-M01  (Default combination)
-C7825-M02
-C7825-M03
-C7825-M04
etc...

When customer searchs the shop for C7285-M03 combination which is not the default one, the results always take the customer to the default combination view which is C7285-M01.

I have tried many options with the same result. This creates many issues with customers purchasing the wrong products.

Is there a way to get the result linked to the correct product search?? 

 

See attached pictures

search-ref.png

default reference.png

opened reference.png

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

  • 1 year later...

Hi

On 5/9/2020 at 6:48 PM, Ezequielb said:

I have Prestashop 1.7.6 and this featured is alredy working with no modules at front and back office( am using a custom theme).

The thing nobody have solved yet is:

A Product was created with reference C7285-M (main product before combinations).

Then combinations were created:
 -C7825-M01  (Default combination)
-C7825-M02
-C7825-M03
-C7825-M04
etc...

When customer searchs the shop for C7285-M03 combination which is not the default one, the results always take the customer to the default combination view which is C7285-M01.

I have tried many options with the same result. This creates many issues with customers purchasing the wrong products.

Is there a way to get the result linked to the correct product search?? 

 

See attached pictures

search-ref.png

default reference.png

opened reference.png

 

Hi

 

Did you solve this? 

Having the same issue.

 

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