Closed (won't fix)
Project:
Commerce Core
Version:
8.x-2.x-dev
Component:
Product
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
19 Jan 2018 at 06:21 UTC
Updated:
27 Mar 2018 at 07:02 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
ywhe commentedComment #3
bojanz commentedVariations always belong to a single product. When the product is deleted, the variations are deleted.
Commerce provides no UI nor API functionality for sharing variations between products.
If you want product group functionality, then it needs to be made one level above products, just like the commerce_product_bundle module does it.
Comment #4
ywhe commentedThis is my patch
Comment #5
bojanz commentedThanks! As I explained in #3, I won't be committing this to Commerce.
Comment #6
skyredwangChange the status to won't fix. Update the issue title to make more sense.
Comment #7
ywhe commentedI need to finish my job.
2937918-2.patch can replace 2937918-1.patch to better solve the problem.
Comment #8
ywhe commentedAnother option (2937918-3.patch) :
remove the variations before removing the entity (because variations_target_id will be removed after deleting the entity, and will not be able to retrieve other entities).
Each variation will be checked for variations, and the variation referenced by other entities will be retained and not References will be deleted.
Comment #9
lisastreeter commented@ywhe It seems like it's taking you a lot of time/effort to make commerce products/variations work as you'd like. Perhaps you might consider making things easier on yourself by rethinking your overall information architecture. I'd suggest creating a new Content Type called "Product" with whatever fields you need for your product information in addition to an entity reference field that references the Commerce Product entity. "Group" would then be one node, and "Dishe"s would be another. As for the Commerce Product type, you can think of them as "variation groups". Each commerce product can have either a single variation or multiple variation, whichever is appropriate. For maximum flexibility, each commerce product could have just a single variation. Then your new, "node" Products could reference any combination of variations.
With this change to your information architecture, multiple node-type Products can refer to the same variations (by referencing the same "variation group" commerce products.) If you delete variations ("commerce products") from one of these "node" Products, it will not be automatically deleted from other products. I think this will achieve the flexibility you need without needing custom code.
It looks like you're relatively new to Drupal; I'm relatively new myself. One of the mistakes I made early on was thinking I needed to solve every problem by writing custom code. (I have a background in php/mysql, so that seemed better and "simpler" than trying to find "workarounds" using existing Drupal core and contrib elements.) Now I find I can do a lot more by creating custom content types (node types) and taxonomies and using contrib modules to solve problems than I originally thought was possible.
Comment #10
ywhe commented@lisastreeter Thank you for your advice, I will seriously consider.
Comment #11
skyredwangThis database connection needs to get the connection from dependency injection, which is a pattern used by D8 and Commerce
Comment #12
skyredwangI had the discussion with @bojanz on Slack. He doesn't think this use case is supported by the current Commerce 2.x. I disagreed with him, my argument is that a site builder can easily change IEF widget to allow referencing existing product variations (This is supported by Drupal itself and IEF), which Commerce has no control of. Therefore, the suit builder is facing this "bug".
Obviously, @bojanz has the final say on what patches get in. But, we have a good intention without causing problems to provide a fix to this bug. Other people who interested in this patch can use composer patch management.
Comment #13
freelock+1
We have this use case. We have a limited number of actual products, but we want to market them in different ways on different landing pages.
For example, we have 3 different monthly plans - "Protection", "Vision", and "Results". We support both Drupal and WordPress on each plan -- however we charge more for WordPress. This leads to 6 different product variations.
For some campaigns, we send people to the "Vision Plan", where customers can select between Drupal or WordPress. For others, we send people to the "Drupal plans" page, with choices between Protection, Vision, and Results. This works fine now with 5 products covering the 6 variations (the 3 levels, the 2 CMSs). It adds a bunch of work to add another layer of abstraction here, if we change to 5 nodes to point to 6 different products with 6 different variations.
Thanks for maintaining the patch!
Comment #14
ywhe commentedI improved the database connection.
Comment #15
skyredwangThis still doesn't use Depedency Injection
Comment #16
ywhe commentedI think the following method is Dependency Injection. But I have no way to complete the query on the commerce_product__variations. I can only query the contents of the commerce_product_variation table. I need help.
My code:
//$connection = \Drupal::service('entity.query')->get('commerce_product_variation'); or
$connection = \Drupal::entityTypeManager()->getStorage('commerce_product_variation')->getQuery();
$query = $connection->condition('variation_id',$target_id);
$result=$query->execute();
Comment #17
freelock@ywhe looking at your patch, it looks like the PreDelete() method gets passed an EntityStorageInterface... assuming that's for Product entities, you can get a query from that (and that is dependency injection right there -- the object is injected into your method, rather than you creating/grabbing one from a global).
Something like this:
Comment #18
ywhe commented@freelock Thanks for your help.
Comment #19
lawxen commentedWe shouldn't change postDelete to preDelete
+ $entity_ids = $query->condition('variations', $item->target_id, 'IN')We should use '=', not 'IN'
Whether this issue is a bug depends on below image:
If commerce don't accept this issue's patch, we should open another issue to disallow above modification about variation's form display.
Comment #20
lawxen commentedChange comment.
Comment #21
lawxen commentedComment #22
lawxen commentedI think the following logic maybe right:
But the origin variation and the “related existing variation” has no difference, entity_reference can't support above vision, So