Hi,
Thanks for building this great commerce add-on. In a view on which I use your module I got this using commerce_discount:

Notice: Undefined index: discount-[discount-rule-name] in commerce_price_components_handler_area_order_total->render() (regel 47 van commerce_price_components/includes/views/handlers/commerce_price_components_handler_area_order_total.inc).

Can you help me please?
I have a discount rule active!

Greetings, Martijn

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Summit’s picture

Hi,

Will this work:

if (empty($this->options['commerce_price_components'][$component['name']])) {

Instead of:

 if (!$this->options['commerce_price_components'][$component['name']])) {

Then the error is gone, but is it the same functionality please?
greetings, Martijn

liupascal’s picture

#1
if (empty($this->options['commerce_price_components'][$component['name']])) { Check if the value is empty or not (http://www.php.net/manual/fr/function.empty.php)

while if (!$this->options['commerce_price_components'][$component['name']])) { will check if it returns false.

I think the issue here is that it actually try to match price component "types" (base_price, discount, fee, shipping....) with the actual price component names.
In discount for instance, $component['name'] will return "discount-Name of your discount" while it will be under the key "discount" in the $this->options['commerce_price_components'] object.

In the current version of -dev we have the following code :

      foreach ($components as $key => $component) {
        if (!isset($display['settings']['commerce_price_components'][$component['name']]) || !$display['settings']['commerce_price_components'][$component['name']]) {
          unset($components[$key]);
        }
      }

I think the problem here remains the same, as it will try to compare the component type "discount" to "discount - My discount".
Not sure how this should be handled though, as tax price component are named like "tax|myTaxName", and discounts as "discount - myDiscountName"

In another module I used a strpos() to search for tax or discount, what do you think ?

liupascal’s picture

joelpittet’s picture

Status: Needs review » Needs work
  1. +++ b/commerce_price_components.module
    @@ -78,7 +78,16 @@ function commerce_price_components_field_formatter_view($entity_type, $entity, $
    -        if (!isset($display['settings']['commerce_price_components'][$component['name']]) || !$display['settings']['commerce_price_components'][$component['name']]) {
    +        if (!isset($display['settings']['commerce_price_components'][$component['name']])
    +          || !$display['settings']['commerce_price_components'][$component['name']]
    +        ) {
    
    @@ -150,17 +159,20 @@ function commerce_price_components_field_info_alter(&$info) {
    -  $property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$name];
    +  $property = & $info[$entity_type]['bundles'][$instance['bundle']]['properties'][$name];
    

    These are unnecessary changes.

  2. +++ b/includes/views/handlers/commerce_price_components_handler_area_line_item_summary.inc
    @@ -79,7 +79,16 @@ function render($empty = FALSE) {
    -            if (!$this->options['commerce_price_components'][$component['name']]) {
    +            if (!isset($this->options['commerce_price_components'][$component['name']])
    +              || !$this->options['commerce_price_components'][$component['name']]
    +            ) {
    
    +++ b/includes/views/handlers/commerce_price_components_handler_area_order_total.inc
    @@ -44,7 +44,16 @@ class commerce_price_components_handler_area_order_total extends views_handler_a
    -              if (!$this->options['commerce_price_components'][$component['name']]) {
    +              if (!isset($this->options['commerce_price_components'][$component['name']])
    +                || !$this->options['commerce_price_components'][$component['name']]
    +              ) {
    

    couldn't this be a simple empty() check?

GoZ’s picture

By default, component name for discounts is not 'discount - Discount Name' but 'discount|Discount Name'.
Pipe is used to separate keys in array keys, and is used in different case like with taxes, so should be the convention.
Here is a patch to take care of that.

kevster’s picture

Many thx @goz - cleared the error for me...

kevster’s picture

I have just applied this patch to a site and it works by showing discounts in the cart again but knocks out the VAT element in the cart so no VAT is applied anywhere?

Im using 20% VAT (UK), price by components and commerce order (component) to calc totals as it gives more flexibility - I have VAT ticked.

Without the patch I get VAT and no discounts showing - with the patch I get discounts line showing but no VAT?

EDIT:
This could be because VAT is used like $component_types['tax|vat'] ?

james.williams’s picture