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 have added following fields to commerce product type of "product"
- Maturity (Taxonomy, set to Product Attributes): has value of Adults, Children
- Room (Taxonomy, set to Product Attributes): has value of Double, Single
- Price dates (type of Date with End date required)
- Price table (Commerce product price table, unlimited)
I've modified the public function defaultFields($bundles) in inline_entity_form/includes/commerce_product.inline_entity_form.inc to show dates and price table:
public function defaultFields($bundles) {
$fields = array();
$fields['title'] = array(
'type' => 'property',
'label' => t('Variation title'),
'visible' => TRUE,
'weight' => 1,
);
$fields['sku'] = array(
'type' => 'property',
'label' => 'Price code',
'visible' => TRUE,
'weight' => 2,
);
// If only one product type is allowed, its fields can be used as columns.
if (count($bundles) == 1) {
$bundle = reset($bundles);
$image_added = FALSE;
$hide_default_price = FALSE; // hide default Commerce price
foreach (field_info_instances('commerce_product', $bundle) as $field_name => $instance) {
$field = field_info_field($field_name);
// If the product has an imagefield, show it.
switch ($field['type']){
case 'image':
if(!$image_added){
$fields[$field_name] = array(
'type' => 'field',
'label' => $instance['label'],
'formatter' => 'image',
'settings' => array('image_style' => 'thumbnail'),
'delta' => 0,
'visible' => TRUE,
'weight' => -10,
);
}
// Don't add any other imagefields. One is enough.
$image_added = TRUE;
break;
case 'datetime':
/* Add field date */
$fields[$field_name] = array(
'type' => 'field',
'label' => $instance['label'], //t('Date'),
'formatter' => 'date_default',
'settings' => array('format_type' => 'short'),
'visible' => TRUE,
'weight' => 80,
);
break;
case 'commerce_price_table':
/* Add field field_price_table */
$fields[$field_name] = array(
'type' => 'field',
'label' => $instance['label'],
'formatter' => 'commerce_multiprice_default',
'settings' => array(),
'visible' => TRUE,
'weight' => 90,
);
if($instance['settings']['commerce_price_table']['hide_default_price'] == 1){
$hide_default_price = TRUE;
}
break;
}
}
// If the type has up to 3 attributes, show them instead of the title field.
$attributes = $this->attributes($bundle);
if (count($attributes) <= 3) {
$fields['title']['visible'] = FALSE;
foreach ($attributes as $field_name => $attribute) {
$field_type = field_info_field_types($attribute['field']['type']);
// Override the default formatter for taxonomy_term_reference.
if ($field_type['default_formatter'] == 'taxonomy_term_reference_link') {
$field_type['default_formatter'] = 'taxonomy_term_reference_plain';
}
$weight = -3;
$fields[$field_name] = array(
'type' => 'field',
'label' => $attribute['instance']['label'],
'formatter' => $field_type['default_formatter'],
'settings' => array(),
'visible' => TRUE,
'weight' => ++$weight,
);
}
}
}
if(! $hide_default_price){
$fields['commerce_price'] = array(
'type' => 'field',
'label' => t('Price'),
'formatter' => 'commerce_price_formatted_amount',
'settings' => array(),
'visible' => TRUE,
'weight' => 99,
);
}
$fields['status'] = array(
'type' => 'property',
'label' => t('Status'),
'visible' => TRUE,
'weight' => 100,
);
return $fields;
}
The inline entity form displays as I expect, but when I add a new variation, the Save is pending forever.
I figure out that the issue is caused by price table because if I show dates only, the Saving task works well.
Comment | File | Size | Author |
---|---|---|---|
inline entity form saving pending.png | 10.85 KB | Anh Kiet | |
inline entity form with commerce price table and dates.png | 36.99 KB | Anh Kiet |
Comments
Comment #1
jenlamptonQuestions about custom code are support requests - not features. Also adjusting status - support requests should not be major.
Comment #2
1kenthomas CreditAttribution: 1kenthomas commentedUpdating title to be descriptive.
I'd suggest:
1) Narrowing down to *just* the price table addition, then nulling out the code, to troubleshoot.
2) Step level debugging, if necessary.
OP: please update this issue if still outstanding.
~1KT
Comment #3
bojanz CreditAttribution: bojanz commentedNo further information provided.