Feature Requests
Share ideas, discuss and vote on requests from other users in community
 

AddProduct api should have unique restraint

jimlongo shared this idea 3 months ago
Under Consideration

The LocalAPI call to 'AddProduct' will duplicate a product if it already exists. This seems problematic. Have to always check if the product already exists.

There should be a unique constraint on "name", so no duplicate products exist.

Comments (2)

photo
1

Hi Jim,

Thanks for your suggestion.

The Product Name is not a unique field in general. It is possible to create products with the same name in the UI, and there are a number of use-cases where this it is important to have duplicate product names.

Can you elaborate on the particular use-case you have for enforcing unique product names via the API only?

photo
1

This is a problem when creating products.

I have a module function that populates a catalog based on SKU entries in our API.

So I get the info and create some products.

```

$command = 'AddProduct';

$postdata = Array

(

[name] => Latitude Premium

[gid] => 3

[type] => other

[paytype] => recurring

[description] => Latitude Premium

[autosetup] => order

[module] => TCS

[configoption1] => yola_prem

[order] => 1

[pricing] => Array

(

[1] => Array

(

[monthly] => 14.99

)

)

)

$results = localAPI($command, $postData, $adminUsername);

```

If that button gets clicked again it will create the exact same product again.

That's not good.

So, check for the one unique thing about that product [configoption1], unfortunately this does not get returned by $command = 'GetProducts';

The suggestion that name should be unique is not really the critical part, it's that something about a product should be unique.

At a minimum at least that $command = 'GetProducts'; should return [configoption1] through [configoption24] so these can be checked against before duplicating the product.