Jump to content
beoutside

The specific price ID is invalid - Product Admin

Recommended Posts

Hello,

My config : Apache/2.4.18 (Ubuntu) - PHP 7.0.33-0ubuntu0.16.04.3 - MySQL 5.7.25-0ubuntu0.16.04.2 - InnoDB

This week-end I've upgraded the shop from MySQL 5.6 to 5.7. I changed the sql_mode to the following removing NO_ZERO_DATE and NO_ZERO_IN_DATE so that the database accepts dates with zeros :

+------------------------------------------------------------------------------------------+
| @@sql_mode                                                                               |
+------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+------------------------------------------------------------------------------------------+
1 row in set (0,00 sec)

 

I tested a bit the website so I went on a product on the back-office and entered a specific price with an unlimited date (0000-00-00 00:00:00). It accepted the line. Then I tried to remove the line and I got the error "The specific price ID is invalid." and the line didn't remove itself.  I tried removing other existing specific price lines but the same error appeared.

I've searched for the error on the Prestashop files and it is on controllers/admin/AdminProductsController.php l.1171 

 public function ajaxProcessDeleteSpecificPrice()
    {
        if ($this->tabAccess['delete'] === '1') {
            $id_specific_price = (int)Tools::getValue('id_specific_price');
            if (!$id_specific_price || !Validate::isUnsignedId($id_specific_price)) {
                $error = Tools::displayError('The specific price ID is invalid.');
            } else {
                $specificPrice = new SpecificPrice((int)$id_specific_price);
                if (!$specificPrice->delete()) {
                    $error = Tools::displayError('An error occurred while attempting to delete the specific price.');
                }
            }
        } else {
            $error = Tools::displayError('You do not have permission to delete this.');
        }

        if (isset($error)) {
            $json = array(
                'status' => 'error',
                'message'=> $error
            );
        } else {
            $json = array(
                'status' => 'ok',
                'message'=> $this->_conf[1]
            );
        }

So if there is no specific price ID (which is not the case) or if my specific price ID isn't validated as an Unsigned ID then the error appears.

To be validated as an Unisgned ID, it's in classes/Validate.php l.696 with : 

    /**
     * Check for an integer validity (unsigned)
     * Mostly used in database for auto-increment
     *
     * @param int $id Integer to validate
     * @return bool Validity is ok or not
     */
    public static function isUnsignedId($id)
    {
        return Validate::isUnsignedInt($id); /* Because an id could be equal to zero when there is no association */
    }

So my ID must be Unisgned if I don't want to have this error. Except that when I go to the SQL table of the specific price, my ID is Unsigned :

    1    id_specific_price Primaire    bigint(11)        UNSIGNED    Non    Aucune    AUTO_INCREMENT

So I don't understand why I got this error. I never got it with MySQL 5.6.

Does someone know if something in MySQL 5.7 prevents my bigint unsigned ID from beeing an UnsignedID ?


 

 

Share this post


Link to post
Share on other sites

Ok, I went a little further and found out that it also checks if it is an INT. As mine is a bigint, I guess that's why the error appears. I had to change from Int to bigint months ago at some point but weirdly MySQL 5.6 let this error sliped. I'm going to change that and check and then tell you if that's it and close the topic!

Share this post


Link to post
Share on other sites

That was it. I added a Validation for bigint on an override of Validate.php

<?php

class Validate extends ValidateCore
{
    /**
     * Check for an integer validity (unsigned)
     *
     * @param int $value Integer to validate
     * @return bool Validity is ok or not
     */
    public static function isUnsignedBigInt($value)
    {
        return ((string)(int)$value === (string)$value && $value < 18446744073709551615 && $value >= 0);
    }

    /* Created because the ID of specific prices
     * is a BIG INT and not an INT anymore
     */
     public static function isUnsignedBigId($id)
    {
        return Validate::isUnsignedBigInt($id); /* Because an id could be equal to zero when there is no association */
    }
}

then applied it to the specific price ID on an ovveride of AdminProductsController.php

  public function ajaxProcessDeleteSpecificPrice()
    {
        if ($this->tabAccess['delete'] === '1') {
            $id_specific_price = (int)Tools::getValue('id_specific_price');
            if (!$id_specific_price || !Validate::isUnsignedBigId($id_specific_price)) {
                $error = Tools::displayError('The specific price ID is invalid.');
            } else {
                $specificPrice = new SpecificPrice((int)$id_specific_price);
                if (!$specificPrice->delete()) {
                    $error = Tools::displayError('An error occurred while attempting to delete the specific price.');
                }
            }
        } else {
            $error = Tools::displayError('You do not have permission to delete this.');
        }

        if (isset($error)) {
            $json = array(
                'status' => 'error',
                'message'=> $error
            );
        } else {
            $json = array(
                'status' => 'ok',
                'message'=> $this->_conf[1]
            );
        }

        die(Tools::jsonEncode($json));
    }

And removeed class_index.php from cache to apply the changes

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More