Unable to delete product

Is there any way to delete product from spryker? There is no functionality in zed as I see.
Why it is not implemented? What was the purpose of it?
Or developers should implement it by themselves as usual?
Or it is somewhere in your code and i need to copy-paste it in my project as you usually recommend? :rofl:

Hello @alexber88,

The delete product feature was never implemented in Spryker. To “hide” a product, you have the following options:

  • Do not assign the product to any store
  • Remove the prices on the product abstract and concrete (product without prices are not shown in the storefront)

We did not build this feature also because of the relationship between a sales order item and a product. In some countries, you must keep your order history for up to 10 years (legal restrictions).

We could implement a soft delete feature that will keep the product in the database but you will not see it anywhere. If such a feature would be interesting to you, please create an idea in our portal https://spryker.ideas.aha.io/ideas

Regards,

Jeremy

@JeremyFourna
If you need to keep orders history with products - this is for what we need order items in my understanding.

And how do you resolve the problem with prices in this case?
If the product price was changed and it is still saleable but with different price? For previous orders that was made with this product - order item price will be not changed. So it will be anyway incorrect.

And in my opinion if the shop manager is not stupid guy and he/she knows that order history should be kept for 10 years - he wouldn’t remove it, isn’t it? :slight_smile:

Also another thing - if there will be 100 mln products in the database? what then?

What is your use case with 100 million product in the database, do you want to be able to delete a single product via the back office or do you want to delete a group of product at once (bulk action)?

This is abstract case :slight_smile:

And yes, I would like to delete one product and I would like to delete group of products from ZED.
But anyway you have neither single removing functionality nor bulk removing.

But you didn’t answer the previous questions.

Hello @alexber88,

After verification, what I said was wrong, the link between a product and a sales order item is not a problem we save all information on the sales order and the corresponding item when an order is placed.

We just do not have the feature to delete a product in the back office, it is as simple as that.

So if in the future we have the delete feature for a product, deleting one should have not impact whatsoever on all other entities, you just deleted a record in the database that will cascade to all connected entities for example if you delete an abstract product, we will also delete.

  • Concrete products
  • Prices
  • Product stock
  • etc…

Have a nice day,

Jeremy

Just to add, deleting the product also means deleting the product from ES and Redis, so deleting is not trivial operation.

What is you need the data later to create a report or something? Best strategy is to mark the product as inactive.

Damijan

Hi @JeremyFourna, @damijanc

What I can say now - you don’t have the cascade deletion in database.
If i delete manually from spy_product_abstract - I get this error
[23503] ERROR: update or delete on table "spy_product_abstract" violates foreign key constraint "spy_product_abstract_store-fk_product" on table "spy_product_abstract_store" Detail: Key (id_product_abstract)=(423) is still referenced from table "spy_product_abstract_store".

So this means that you don’t have any action when deleting the product from the table.
I also checked in database the database table settings - there is nothing regarding cascade deletion.
For example here is the scrennshot of spy_price_product table.


This is just clean spryker installation in docker.

@damijanc I don’t care if it is trivial operation or not. There SHOULD be a possibility to delete product from E-commerce shop.
Do you know what is CRUD? Create, read, update, DELETE. So you have only CRU? I don’t understand your logic.
Or imagine that in the offline (physical) supermarket there is no possibility to remove product from the product shelf. You can only “hide” it. Color in the color of the shelf, hide it behind the other products or whatever. Do you think it is normal situation?

You can either truncate the table with a cascade options like

TRUNCATE some_table CASCADE;

or you can modify the schema to allow cascade in your database.

<foreign-key foreignTable="book" onDelete="CASCADE">
    <reference local="book_id" foreign="id"/>
  </foreign-key>

or you can write a series of delete statements and go from the child up. It is really not a big deal.

Be aware that by deleting it from DB you still need to remove it from Elastic search and Redis.

Damijan

Why should I modify something in YOUR database schema? I shouldn’t care about it. Why it was not done OOTB?

Ok. On production website. Good option. :+1: :grin:
And what if I need to remove only one product? :slight_smile: Imagine that I’m a website manager and I don’t need anymore one product. What to do?)

I hope it was a joke? :slight_smile:
If not - than I can imagine how do you delete categories. Executing over 100500 sql queries to delete from different tables because there is no cascade deletion.

console sync:data should do the trick, isn’t it? :slight_smile:

Greetings Alex!

In many cases, you would be totally right with what you say!
However, there is a bit more here at play:

First of all, I would highly discourage shop operators from directly accessing the database for a lot of reasons! :slight_smile:

Not removing, but rather deactivating, products comes from accumulated decades of e-commerce experience. Because it usually entails a whole lot more of business implications than you would usually make the database aware of. Mostly, the database is merely a persistence mechanism and should not necessarily have knowledge about some of the higher concepts, that are embedded in the business logic.

Furthermore, but also related, we are not providing a simple CRUD application here. Cascading a deletion within the database instead of going through a layer of business rules, could break parts of the application, like Publish&Synchronize, our CQRS implementation, that relies on higher architectural concepts.

If you like, I would gladly discuss these things with you in more detail in a better-suited format!

Best
Marco

Hello Marco.

I think nothing to discuss here anymore. This is an architectural slip if product removing can break something. And as for me it looks one of the big disadvatages of spryker.