Jump to content

Forcing ID when using the webservice


xbenjii

Recommended Posts

Is there any way to override the auto increment and add my own ID for any resource?

 

I have the following below but it's not using the id. I've also tried $fields->id_product_attribute.

    public function addProductCombination($schema, $id, $options) {
        $fields = $schema->children()->children();
        $results = [];

        foreach ($options as $option) {
            $fields->id = $option->option_id;
            $fields->id_product = $id;
            $fields->price = $option->price;
            $fields->weight = $option->shipping_weight;
            $fields->associations->product_option_values->product_option_values[0]->id = $this->findType($option->option_types);
            $fields->minimal_quantity = 1;
            $opt = [
                'postXml' => $schema->asXML(),
                'resource' => 'combinations'
            ];

            try {
                $results[] = $this->presta->add($opt);
            } catch (PrestaShopWebserviceException $ex) {
                die($ex->getMessage());
            }
        }

        return $results;
    }
Link to comment
Share on other sites

  • 1 month later...

i have no idea what you're trying to achieve

you want to change the id of the object  or what?

if so, im affraid that due to the database consistency things - it's not possible

 

Instead of auto-increment kicking in, I want to force the ID of a product.

Link to comment
Share on other sites

I guess you just want to add additional field to database and object which would be unique to your attribute or product?

 

If that's the case, you just should add additional field to object, make sure it is added to object's structure and use it as simple value.

 

However, you will not probably make it auto_increment in mysql without breaking all tables structure as many errors can show up if default PrestaShop's ids will be changed.

Edited by Richard S (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...