Hi
I have a problem with deleting products in Commerce module.
How to reproduce
Install and enable Drupal Commerce and related modules, install and enable ds and ds_extras, create product and then delete it. On deletion page ( /admin/commerce/products/.../delete ), instead of confirmation message, you will see something like:
Notice: Undefined index: #commerce_product in ds_extras_render_panel_layout() (line 934 of /web/eboost/staging/team-poland/smartrecovery.be/sites/all/modules/ds/modules/ds_extras/ds_extras.module).
Error
Error messageEntityMalformedException: Missing bundle property on entity of type commerce_product. in entity_extract_ids() (line 7539 of /web/eboost/staging/team-poland/smartrecovery.be/includes/common.inc).
The website encountered an unexpected error. Please try again later.
Debugging
After debugging I got to the following results:
1. Commerce Product code tries to render a product (commerce_product.forms.inc:210):
$content = entity_view('commerce_product', array($product->product_id => $product));
$form = confirm_form($form,
t('Are you sure you want to delete %title?', array('%title' => $product->title)),
'',
drupal_render($content) . '<p>' . t('Deleting this product cannot be undone.', array('@sku' => $product->sku)) . '</p>',
t('Delete'),
t('Cancel'),
'confirm'
);
2. In fact, $content is generated with DrupalCommerceEntityController::view() (entity_view is just a wrapper for this method). DrupalCommerceEntityController::view() puts entity data into "#entity" key in returned array:
build += array(
'#theme' => 'entity',
'#entity_type' => $this->entityType,
<strong>'#entity' => $entity,</strong>
'#view_mode' => $view_mode,
'#language' => $langcode,
'#page' => $page,
3. $content is processed by Drupal theming mechanisms and gets to ds_extras_render_panel_layout() function. This function expects that entity data is put into "#$entity_type" field, where $entity_type == 'commerce_product'
The code already contains workarounds for similar issues for user and taxonomy term entities (see issue #1360480: Notice: Undefined index: #taxonomy_term in ds_extras_render_panel_layout() (line 904 ).
Below is code that implements workaround for this issue.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | ds_extras-fix_commerce_compatibility_EntityMalformedException-1698236-1.patch | 683 bytes | lklimek |
Comments
Comment #1
lklimek commentedPatch attached (against latest dev, but also applies without problems to 7.x-1.5).
To apply:
Comment #2
swentel commentedThanks, committed and pushed!
Comment #3
swentel commentedComment #3.0
swentel commentedFixed link to related issue