Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm back to extending commerce_stripe to work with marketplace.
I'm implementing hook_commerce_cart_product_add
to disallow products from different stores in order to simplify debug.
However, I have two line items in my cart, originating from products with stores 1 and 2 in my cart, yet the $order object I see when I add a third item inside hook_commerce_cart_product_add
only has commerce_store
's target_id
set to 1.
But both should be set, right? Seems to me that the commerce_store array on the order object should have both stores set.
The question is whether this is the expected behavior or not.
Comments
Comment #1
glass.dimly CreditAttribution: glass.dimly commentedI've had a chance to read through the commerce_marketplace_paypal module and get caught up on development of this module.
The code is excellent to read through, and it's given me a sense of how to proceed with the commerce_marketplace_stripe module for chained payments.
Forget about this question, I'll open this later if needed.
Comment #2
glass.dimly CreditAttribution: glass.dimly commentedI'm re-opening this issue, I'm on tag v0.0.1.
Order store_id is getting set erratically, either to be store_id 1 or unset after adding a product from store_id 2. I'm adding items to the cart and then viewing the cart in the order interface.
I'll see if I can't provide some more useful debug information here.
Comment #3
glass.dimly CreditAttribution: glass.dimly commentedI believe that what is happening here is that in
commerce_marketplace_cart_product_add
commerce_marketplace_cart_get_splitter_field_instances($product->type)
is not returning TRUE for my commerce_store field on my custom product variation.That means that store is not getting added to the order object.
I was using a hook_commerce_cart_product_add to set the store id on the order, but now I'm using a rule that wants to fire earlier in the call stack, and my store id is not set that early. My payments are set to send to "main store."
I could use some advice here.
Comment #4
glass.dimly CreditAttribution: glass.dimly commentedTurns out that because
$instance['commerce_marketplace_cart_settings']
is empty on commerce_store,commerce_marketplace_cart_field_instance_splitter_settings
is returning'order_splitter_field' => FALSE
, which causescommerce_marketplace_cart_field_instance_is_splitter
to returnFALSE
.I'm going to have a look at
commerce_marketplace_cart_form_field_ui_field_edit_form_alter
and check out whycommerce_marketplace_cart_settings
is not getting set.I had previously been setting the commerce_store field on the order in a hook_commerce_cart_product_add to work around the fact that commerce_store was not getting set on the order because I had not understood the purpose of the splitter settings and was not using the splitter functionality.
I was unable to replicate the issue on a fresh install from the marketplace profile but seeing it working properly was informative.
I've now disable and enabled the whole commerce_marketplace suite, no change.
Please pardon my verbosity, sometimes writing this all out helps me think through it.
Comment #5
glass.dimly CreditAttribution: glass.dimly commentedSplitter cannot be set on commerce_store instances because the field instance is locked (empty($form['locked']) is false).
This would be true of any already-created commerce_store instance. Should this setting be moved another place? Seems problematic that it cannot be set/unset. How should this be handled?
This code is a work-around that sets the commerce_marketplace_cart_settings on commerce_store field instances on each commerce_product.
Should this be added to an upgrade hook? Or is my database's state as a result of code changes that will not be relevant? Can't hurt, anyways.
Comment #6
maciej.zgadzaj CreditAttribution: maciej.zgadzaj commentedThat's true,
commerce_store
field was locked initially, and I have unlocked it in one of the previous commits, to be able to configure it for cart splitting. There was no upgrade path though for previous installations with this field already locked, as I guess was your case.This commit adds
hook_update()
implementation to unlock thecommerce_store
field and configure it as the cart splitter on all bundles ofcommerce_product
entity type - please let me know if it helps.Comment #7
glass.dimly CreditAttribution: glass.dimly commentedI ran this update when I updated, but it was not needed, because my queries set the splitter field on store. However, I got this error:
Comment #9
glass.dimly CreditAttribution: glass.dimly commentedI'm marking this issue as closed/fixed. Let's re-open if someone experiences this issue again.