Jump to content

PS 8 - Customer.php getSimpleAddressSql generates incorrect SQL


mxxmus

Recommended Posts

In 8.0 was added ORDER BY expression.
But it was not considered next optional adding of filtering by id_address:
 

        $sql = 'SELECT DISTINCT
                      a.`id_address` AS `id`,
                      a.`alias`,
                      a.`firstname`,
                      a.`lastname`,
                      a.`company`,
                      a.`address1`,
                      a.`address2`,
                      a.`postcode`,
                      a.`city`,
                      a.`id_state`,
                      s.name AS state,
                      s.`iso_code` AS state_iso,
                      a.`id_country`,
                      cl.`name` AS country,
                      co.`iso_code` AS country_iso,
                      a.`other`,
                      a.`phone`,
                      a.`phone_mobile`,
                      a.`vat_number`,
                      a.`dni`
                    FROM `' . _DB_PREFIX_ . 'address` a
                    LEFT JOIN `' . _DB_PREFIX_ . 'country` co ON (a.`id_country` = co.`id_country`)
                    LEFT JOIN `' . _DB_PREFIX_ . 'country_lang` cl ON (co.`id_country` = cl.`id_country`)
                    LEFT JOIN `' . _DB_PREFIX_ . 'state` s ON (s.`id_state` = a.`id_state`)
                    ' . ($shareOrder ? '' : Shop::addSqlAssociation('country', 'co')) . '
                    WHERE
                        `id_lang` = ' . (int) $idLang . '
                        AND `id_customer` = ' . (int) $this->id . '
                        AND a.`deleted` = 0
                        AND a.`active` = 1
                    ORDER BY a.`alias`';

        if (null !== $idAddress) {
            $sql .= ' AND a.`id_address` = ' . (int) $idAddress;
        }


So now we have the following SQL code (example):

SELECT DISTINCT
                      a.`id_address` AS `id`,
                      a.`alias`,
                      a.`firstname`,
                      a.`lastname`,
                      a.`company`,
                      a.`address1`,
                      a.`address2`,
                      a.`postcode`,
                      a.`city`,
                      a.`id_state`,
                      s.name AS state,
                      s.`iso_code` AS state_iso,
                      a.`id_country`,
                      cl.`name` AS country,
                      co.`iso_code` AS country_iso,
                      a.`other`,
                      a.`phone`,
                      a.`phone_mobile`,
                      a.`vat_number`,
                      a.`dni`
                    FROM `ps_address` a
                    LEFT JOIN `ps_country` co ON (a.`id_country` = co.`id_country`)
                    LEFT JOIN `ps_country_lang` cl ON (co.`id_country` = cl.`id_country`)
                    LEFT JOIN `ps_state` s ON (s.`id_state` = a.`id_state`)
                     INNER JOIN ps_country_shop country_shop
        ON (country_shop.id_country = co.id_country AND country_shop.id_shop = 1)
                    WHERE
                        `id_lang` = 1
                        AND `id_customer` = 2
                        AND a.`deleted` = 0
                        AND a.`active` = 1
                    ORDER BY a.`alias` AND a.`id_address` = 16663

And as result will be selected all the customer addresses, but not the one filtered by id_address.

 

PS. I'm new on this forum. So small question. Is here right place to write bug reports to have them found and fixed by Prestashop developers?

Link to comment
Share on other sites

Hi 

And welcome to the forum. It is right place to place bug so others could talk about. But PrestaShop developers do not come here much.

You can post to prestashop.slack.com but real proper way is to contribute to GitHub https://github.com/PrestaShop/PrestaShop

Check readme file there is part 

Quote

Reporting Issues

Our bugtracker is on GitHub. We encourage you to create detailed issues as soon as you see them.

Read our Contribute by reporting issues guide for details and tips.

https://github.com/PrestaShop/PrestaShop#reporting-issues

 

Thank you

  • Like 1
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...