Modify

Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#1698 closed Bug/Fehler (fixed)

warning beim Kauf aus Kundenkonto, Attribute ohne IDs

Reported by: info@… Owned by: somebody
Priority: normal Milestone: modified-shop-2.0.5.0
Component: Shop Version: trunk
Keywords: Cc:
Blocked By: Blocking:

Description

Hi,

vielleicht habt ihr schon eine Lösung vorliegen.
Folgendes Szenario:
Ein alter Shop wurde auf 2.0.x aktualisiert.
In der damaligen Shopversion wurden noch keine IDs zu Attributen einer Bestellung gespeichert.
Nutzen Kunden nun die Funktion, Bestellungen aus dem Kundenkonto in den Warenkorb zu legen, gibt es eine PHP-Warnung:

in_array() expects parameter 2 to be array, null given in File [...] includes/classes/shopping_cart.php on Line: 969

Ursache: da die Option-IDs nicht gespeichert wurden, ist diese mit 0 vorbelegt. Ein Attributwert wird nun in einem Array gesucht, dass nicht existiert, weil $option 0 ist

if (!in_array($value,$products_attributes_array[$pID][(int)$option])) {}

Die Bestellung wird dann nicht oder nicht vollständig in den Warenkorb gelegt.

Wie können wir das bestmöglich korrigieren?

Mein Ansatz wäre dieser:
1.) Prüfen, ob es überhaupt ein Array gibt:

includes/classes/shopping_cart.php

function validate_attributes($products_id, $attributes, $flag = '') {
    static $products_attributes_array;
    if (!is_array($products_attributes_array)) {
      $products_attributes_array = array();
    }

    $check = true;
    if (is_array($attributes) && count($attributes)) {
      $pID = (int)$products_id;
      if (!isset($products_attributes_array[$pID])) {
        $products_attributes_array[$pID] = $this->create_products_attributes_array($pID);
      }
if(!array_key_exists((int)$option, $products_attributes_array[$pID])) {
  return false;
}
      foreach($attributes as $option => $value) {
        if (!in_array($value,$products_attributes_array[$pID][(int)$option])) {
          $check = false;
          break;
        }
      }
    }
    return $check;
  }

2.) Um das Einkaufserlebnis hoch zu halten in der cart_action.php versuchen die Attribut-IDs zu ermitteln, wenn diese noch mit "0" in der Datenbank stehen.

Gibt es Einwände?

Viele Grüße
Andreas

Attachments (0)

Change History (6)

comment:1 by Andreas Guder, 6 years ago

Resolution: fixed
Status: newclosed

In 12287:

fix #1698 - try to find options ids by name

comment:3 by Andreas Guder, 6 years ago

In 12288:

fix #1698 - update missing option-ids in database

comment:4 by Torsten Riemer, 6 years ago

Milestone: modified-shop-2.0.5.0
Resolution: fixed
Status: closedreopened

Ich öffne das Ticket nochmal, da der Code nochmal formatiert werden muss gemäß PSR-2.

comment:5 by Andreas Guder, 6 years ago

Resolution: fixed
Status: reopenedclosed

In 12291:

fix #1698 - psr-2

comment:6 by Gerhard Waldemair, 6 years ago

In 12293:

fix #1698

comment:7 by Hetfield, 5 years ago

In 13560:

fix r12293 (fix #1698) - remove double AND in sql query

Modify Ticket

Action
as closed The owner will remain somebody.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.