Wie kann die Funktion in "inc/xtc_get_products.inc.php" überladen werden?

Thema wurde von TP_Rhs, 2. Februar 2023 erstellt.

  1. TP_Rhs

    TP_Rhs Mitglied

    Registriert seit:
    11. April 2019
    Beiträge:
    21
    Danke erhalten:
    1
    Danke vergeben:
    4
    Hallo,

    für ein Preismodul müsste ich die "inc/xtc_get_products.inc.php" verändern.
    Mit "Overloads" komme ich da ja meines Erachtens nicht weiter oder?
    Für einen Tipp zur Vorgehensweise wäre ich sehr dankbar.

    Schönen Gruß
    Thomas
     
  2. Anonymous

    Anonymous Erfahrener Benutzer
    Mitarbeiter

    Registriert seit:
    22. Juni 2011
    Beiträge:
    4.760
    Danke erhalten:
    1.748
    Danke vergeben:
    137
    Ich habe Zweifel, dass xtc_get_products() überhaupt die richtige Baustelle ist. Bitte mach mal ein, zwei Schritte rückwärts und erläutere etwas ausführlicher, was du da tust und was dein eigentliches Ausgangsproblem ist.
     
  3. TP_Rhs

    TP_Rhs Mitglied

    Registriert seit:
    11. April 2019
    Beiträge:
    21
    Danke erhalten:
    1
    Danke vergeben:
    4
    Ziel ist die Darstellung von produktübergreifenden Staffelpreisen:
    Wir bekommen aus der Wawi die Rabattgruppe geliefert und speichern dies im Feld "rabattgruppen" in der Tabelle "products".
    Um auf Basis der kumulierten Menge aller Artikel einer Preisgruppe die Preisermittlung durchzuführen, verfahren wir wie folgt:
    Code:
    diff --git a/inc/xtc_get_products.inc.php b/inc/xtc_get_products.inc.php
    --- a/inc/xtc_get_products.inc.php   
    +++ b/inc/xtc_get_products.inc.php    (date 1675329553788)
    @@ -26,20 +26,54 @@
           {
               return false;
           }
    - 
    +      $rabattgruppen_array = array();
    +      foreach($session['cart']->contents as $products_id_old => $value_old)
    +      {
    +          $product_query_old = xtc_db_query("select products_id, products_price, products_discount_allowed, products_tax_class_id, products_weight, rabattgruppen from " . TABLE_PRODUCTS . " where products_id='" . xtc_db_input(xtc_get_prid($products_id_old)) . "'");
    +          if($product_old = xtc_db_fetch_array($product_query_old))
    +          {
    +              $new_products_array[$products_id_old] = array("qty" => $session['cart']->contents[$products_id_old]['qty'], "rabattgruppe" => $product_old['rabattgruppen']);
    +              if (array_key_exists($product_old['rabattgruppen'], $rabattgruppen_array))
    +              {
    +                  $new_value = $rabattgruppen_array[$product_old['rabattgruppen']]['qty'] + $_SESSION['cart']->contents[$products_id_old]['qty'];
    +                  $rabattgruppen_array[$product_old['rabattgruppen']] = array("qty" => $new_value);
    +              }
    +              else
    +              {
    +                  if ($product_old['rabattgruppen'] != "")
    +                  {
    +                      $rabattgruppen_array[$product_old['rabattgruppen']] = array("qty" => $_SESSION['cart']->contents[$products_id_old]['qty']);
    +                  }
    +              }
    +          }
    +      }
             $products_array = array();
             reset($session);
             foreach($session['cart']->contents as $products_id => $value) {
               $products_query = xtc_db_query("select p.products_id, pd.products_name,p.products_image, p.products_model, p.products_price, p.products_discount_allowed, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id='" . xtc_get_prid($products_id) . "' and pd.products_id = p.products_id and pd.language_id = '" . $_SESSION['languages_id'] . "'");
               if ($products = xtc_db_fetch_array($products_query)) {
                 $prid = $products['products_id'];
    +
    +              if ($rabattgruppen_array[$new_products_array[$products_id]['rabattgruppe']]['qty'] == "")
    +              {
    +                  $preisberechnungs_qty = $value['qty'];
    +
    +              }
    +              else
    +              {
    +                  $preisberechnungs_qty = $rabattgruppen_array[$new_products_array[$products_id]['rabattgruppe']]['qty'];
    +              }
    +
                 // dirty workaround
                 $xtPrice = new xtcPrice($session['currency'],$session['customers_status']['customers_status_id']);
                 $products_price=$xtPrice->xtcGetPrice($products['products_id'],
                                               $format=false,
    -                                          $session['cart']->contents[$products_id]['qty'],
    +                                          $preisberechnungs_qty,
                                               $products['products_tax_class_id'],
                                               $products['products_price']);
     
  4. Anonymous

    Anonymous Erfahrener Benutzer
    Mitarbeiter

    Registriert seit:
    22. Juni 2011
    Beiträge:
    4.760
    Danke erhalten:
    1.748
    Danke vergeben:
    137
    Wie kommt ihr dabei auf die xtc_get_products()?? Die Funktion wird im Shopsystem kaum irgendwo benutzt. Mit hoher Wahrscheinlichkeit wäre der richtigere Ansatz, die xtcPrice-Klasse zu überladen.
     
  5. TP_Rhs

    TP_Rhs Mitglied

    Registriert seit:
    11. April 2019
    Beiträge:
    21
    Danke erhalten:
    1
    Danke vergeben:
    4
    Danke für den richtigen Ansatz