v2.7.x Überflüssige Datenbankabfrage in "_addAttributes"

Thema wurde von Avenger, 11. August 2016 erstellt.

  1. Avenger

    Avenger G-WARD 2012/13/14/15

    Registriert seit:
    26. April 2011
    Beiträge:
    4.771
    Danke erhalten:
    1.478
    Danke vergeben:
    89
    In "CheckoutProcessProcess" wird in Methode "_addAttributes" eine überflüssige DB-Abfrage verwendet.


    Code:
      protected function _addAttributes(array $product, array &$orderItemAttributesArray)
      {
        if(isset($product['attributes']))
        {
          foreach($product['attributes'] as $attribute)
          {
            $query = "SELECT
            popt.products_options_name,
            poval.products_options_values_name,
            pa.options_values_price,
            pa.price_prefix,
            pa.options_id,
            pa.options_values_id
            FROM
            " . TABLE_PRODUCTS_OPTIONS . " popt,
            " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval,
            " . TABLE_PRODUCTS_ATTRIBUTES . " pa
            WHERE
            pa.products_id = '" . (int)$product['id'] . "' AND
            pa.options_id = '" . (int)$attribute['option_id'] . "' AND
            pa.options_id = popt.products_options_id AND
            pa.options_values_id = '" . (int)$attribute['value_id'] . "' AND
            pa.options_values_id = poval.products_options_values_id AND
            popt.language_id = '" . (int)$_SESSION['languages_id'] . "' AND
            poval.language_id = '" . (int)$_SESSION['languages_id'] . "'";
    
            $result = xtc_db_query($query);
    
            /** @var OrderObjectService $orderObjectService */
            $orderObjectService = StaticGXCoreLoader::getService('OrderObject');
    
            if(xtc_db_num_rows($result))
            {
              $row = xtc_db_fetch_array($result);
    
              $orderItemAttribute = $orderObjectService->createOrderItemAttributeObject(new StringType($row['products_options_name']),
                new StringType($row['products_options_values_name']));
              $orderItemAttribute->setPrice(new DecimalType($row['options_values_price']));
              $orderItemAttribute->setPriceType(new StringType($row['price_prefix']));
    
              $orderItemAttributesArray[] = $orderItemAttribute;
            }
            else // GX-Customizer set data will be connected to empty attribute
            {
              $orderItemAttribute = $orderObjectService->createOrderItemAttributeObject(new StringType(''),
                new StringType(''));
    
              $orderItemAttributesArray[] = $orderItemAttribute;
            }
          }
        }
      }
    
    Für ein Attribut hat die Variable "$attribute" folgenden Wert:

    Code:
    : array =
      option: string = Varianten
      value: string = silber
      option_id: long = 1
      value_id: string = 34
      prefix: string = -
      price: string = 0.0000
    Nach der DB-Abfrage hat die Variable "$row" folgenden Wert:


    Code:
      products_options_name: string = Varianten
      products_options_values_name: string = silber
      options_values_price: string = 0.0000
      price_prefix: string = -
      options_id: string = 1
      options_values_id: string = 34
    D.h., die gleichen Werte wie "$attribute", nur mit anderen Namen...
     
  2. Avenger

    Avenger G-WARD 2012/13/14/15

    Registriert seit:
    26. April 2011
    Beiträge:
    4.771
    Danke erhalten:
    1.478
    Danke vergeben:
    89
    Die Felder "options_id" und "options_values_id" in der "products_attributes"-Tabelle werden nicht gesetzt.

    "protected function _addAttributes" in "CheckoutProcessProcess" sollte wie folgt erweitert werden:

    Code:
              $orderItemAttribute->setOptionId(new IdType((int)$row['options_id']));
              $orderItemAttribute->setOptionValueId(new IdType((int)$row['options_values_id']));