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

glass.dimly’s picture

Category: Bug report » Support request
Status: Active » Closed (works as designed)

I'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.

glass.dimly’s picture

Category: Support request » Bug report
Status: Closed (works as designed) » Active

I'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.

glass.dimly’s picture

I 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.

glass.dimly’s picture

Turns 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 causes commerce_marketplace_cart_field_instance_is_splitter to return FALSE.

I'm going to have a look at commerce_marketplace_cart_form_field_ui_field_edit_form_alter and check out why commerce_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.

glass.dimly’s picture

Splitter 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.

  $result = db_select('field_config_instance', 'f')
    ->fields('f', array('data', 'id'))
    ->condition('field_name', 'commerce_store')
    ->condition('entity_type', 'commerce_product')
    ->execute();

  foreach($result as $instance){
    $data = unserialize($instance->data);
    //All commerce_store instances on commerce_product types should have a commerce_marketplace_cart_settings. If not, set them.
    if(!is_array($data['commerce_marketplace_cart_settings'])) {
      $data['commerce_marketplace_cart_settings']['order_splitter_field'] = 1;
      $data['commerce_marketplace_cart_settings']['cart_splitter_field'] = 0;
      $data = serialize($data);
      db_update('field_config_instance')
        ->fields(array(
          'data' => $data,
        ))
        ->condition('id', $instance->id, '=')
        ->execute();
    }
  }
maciej.zgadzaj’s picture

Status: Active » Needs review

That'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 the commerce_store field and configure it as the cart splitter on all bundles of commerce_product entity type - please let me know if it helps.

glass.dimly’s picture

I 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:

 Commerce_marketplace  7000  Unlock 'commerce_store' field and configure it as cart splitter on all  bundles of 'commerce_product' entity type.
Do you wish to run all pending updates? (y/n): y

Fatal error: Call to undefined method i18n_object_wrapper::strings_update() in .../profiles/commerce_kickstart/modules/contrib/i18n/i18n_string/i18n_string.module on line 851

Call Stack:
    0.0005     241008   1. {main}() /usr/local/Cellar/drush/HEAD/libexec/drush.php:0
    0.0351    2480128   2. drush_main() /usr/local/Cellar/drush/HEAD/libexec/drush.php:16
    0.4452    9025064   3. Drush\Boot\DrupalBoot->bootstrap_and_dispatch() /usr/local/Cellar/drush/HEAD/libexec/drush.php:76
    2.7526   64136080   4. drush_dispatch(array(31), ???) /usr/local/Cellar/drush/HEAD/libexec/lib/Drush/Boot/DrupalBoot.php:46
    3.3842   67772760   5. call_user_func_array:{/usr/local/Cellar/drush/HEAD/libexec/includes/command.inc:178}(string(13), array(2)) /usr/local/Cellar/drush/HEAD/libexec/includes/command.inc:178
    3.3842   67773336   6. drush_command(string(5), string(5)) /usr/local/Cellar/drush/HEAD/libexec/includes/command.inc:178
    3.3850   67777648   7. _drush_invoke_hooks(array(31), array(2)) /usr/local/Cellar/drush/HEAD/libexec/includes/command.inc:210
    3.3885   67845472   8. call_user_func_array:{/usr/local/Cellar/drush/HEAD/libexec/includes/command.inc:359}(string(33), array(2)) /usr/local/Cellar/drush/HEAD/libexec/includes/command.inc:359
    3.3885   67845944   9. drush_core_updatedb_batch_process(string(5), string(5)) /usr/local/Cellar/drush/HEAD/libexec/includes/command.inc:359
    4.9824   76839296  10. _update_batch_command(string(5)) /usr/local/Cellar/drush/HEAD/libexec/commands/core/core.drush.inc:1130
   11.9544   84535664  11. drush_batch_command(string(5)) /usr/local/Cellar/drush/HEAD/libexec/commands/core/drupal/update_7.inc:242
   11.9603   84583624  12. _drush_batch_command(string(5)) /usr/local/Cellar/drush/HEAD/libexec/includes/batch.inc:90
   11.9607   84589848  13. _drush_batch_worker() /usr/local/Cellar/drush/HEAD/libexec/commands/core/drupal/batch.inc:101
   11.9623   84670216  14. call_user_func_array:{/usr/local/Cellar/drush/HEAD/libexec/commands/core/drupal/batch.inc:149}(string(19), array(4)) /usr/local/Cellar/drush/HEAD/libexec/commands/core/drupal/batch.inc:149
   11.9623   84670432  15. drush_update_do_one(string(20), long, array(0), class DrushBatchContext) /usr/local/Cellar/drush/HEAD/libexec/commands/core/drupal/batch.inc:149
   11.9624   84672112  16. commerce_marketplace_update_7000(array(0)) /usr/local/Cellar/drush/HEAD/libexec/commands/core/drupal/update_7.inc:73
   11.9710   85373272  17. field_update_field(array(16)) .../sites/all/modules/contrib/commerce_marketplace/commerce_marketplace.install:28
   12.2110   87395384  18. module_invoke_all(string(18), array(17), array(15), bool) .../modules/field/field.crud.inc:294
   19.1817   93930816  19. call_user_func_array:{.../includes/module.inc:895}(string(29), array(3)) .../includes/module.inc:895
   19.1817   93931368  20. i18n_field_field_update_field(array(17), array(15), bool) .../includes/module.inc:895
   19.1817   93931400  21. i18n_field_field_update_strings(array(17)) .../profiles/commerce_kickstart/modules/contrib/i18n/i18n_field/i18n_field.module:363
   19.1817   93931488  22. i18n_string_object_update(string(5), array(17), ???) .../profiles/commerce_kickstart/modules/contrib/i18n/i18n_field/i18n_field.module:370

Drush command terminated abnormally due to an unrecoverable error.                                                                                                     [error]
Error: Call to undefined method i18n_object_wrapper::strings_update() in
/.../profiles/commerce_kickstart/modules/contrib/i18n/i18n_string/i18n_string.module, line 851
The external command could not be executed due to an application error.                                                                                                [error]
'all' cache was cleared.                                                                                                                                               [success]
The administrator role has been reset for all permissions.                                                                                                             [status]
	Finished performing updates.                                                                                                                                           [ok]
$ 

  • maciej.zgadzaj committed 005c400 on 7.x-1.x
    Issue #2488832: Unlock commerce_store field and configure it as cart...
glass.dimly’s picture

Status: Needs review » Closed (fixed)

I'm marking this issue as closed/fixed. Let's re-open if someone experiences this issue again.