shopping_cart.php überladen geht nicht?

Thema wurde von MBJ, 20. Januar 2016 erstellt.

  1. MBJ
    MBJ Aktives Mitglied
    Registriert seit:
    31. Januar 2012
    Beiträge:
    43
    Danke erhalten:
    3
    Danke vergeben:
    10
    Hi Forum,
    ich versuche die
    "includes/classes/shopping_cart.php"

    zu überladen.

    Ich habe dazu folgenden Ordner angelegt:
    "user_classes/overloads/shopping_cart"

    Meine Datei heißt:
    "shoppingCartClassei.inc.php"

    und darin wird folgendes definiert:
    PHP:
    class shoppingCartClassei extends shoppingCartClassei_parent{}

    Auch nach dem Löschen des Caches wird die Klasse einfach nicht überladen. Die xtcPrice hab ich allerdings erfolgreich überladen! Kann man die shopping_cart.php nicht überladen?

    Vielen Dank an euch
     
  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
    In der Klasse ist ja auch keine Eigenschaft oder Methode definiert, was soll er da überladen?
     
  3. MBJ
    MBJ Aktives Mitglied
    Registriert seit:
    31. Januar 2012
    Beiträge:
    43
    Danke erhalten:
    3
    Danke vergeben:
    10
    Hi Avenger,
    ich würde gerne in der shopping_cart.php die function calculate überschreiben. Natürlich ist mein Beispiel hier blöd, da ich wirklich keine Methoden drinnen hatte. Mir gings darum die Dateinamen, Klassennamen und Pfade zu verdeutlichen. Ich würde gerne die function calculate() überschreiben. Ich will in der Preisberechnung etwas ändern.
    In (ca.) Zeile 21 der function calculate() wird der Preis errechnet:
    PHP:
    $products_price $xtPrice->xtcGetPrice($products_id$format false$qty$product['products_tax_class_id'], $product['products_price'], 00truetrue);
    Hier muss je nach Produkt durch 100 dividiert werden. Aber wie gesagt das Überladen klappt hier nicht, der Preis wird nicht korrigiert. Wenn ichs in der originalen shopping_cart.php ändere stimmts aber!!
    Beispiel function calculate:
    PHP:
    function calculate()
        {
            global 
    $xtPrice;

            
    $this->total 0;
            
    $this->weight 0;
            
    $this->tax = array();

            if(!
    is_array($this->contents))
            {
                return 
    0;
            }

            
    reset($this->contents);
            while(list (
    $products_id, ) = each($this->contents))
            {
                
    $qty $this->contents[$products_id]['qty'];

                
    // products price
                
    $product_query xtc_db_query("select products_id, products_price, products_discount_allowed, products_tax_class_id, products_weight from " TABLE_PRODUCTS " where products_id='" xtc_db_input(xtc_get_prid($products_id)) . "'");
                if(
    $product xtc_db_fetch_array($product_query))
                {
                    
    $products_price $xtPrice->xtcGetPrice($products_id$format false$qty$product['products_tax_class_id'], $product['products_price'], 00truetrue);
    # Mit if soll hier $products_price durch 100 dividiert wereen
                    
    $this->total += $products_price $qty;

                    
    # set combis weight
                    
    $t_properties_weight $this->properties_weight($products_id$product['products_weight']);
                    if(
    $t_properties_weight == 0)
                    {
                        
    $t_properties_weight $product['products_weight'];
                    }
                    
    $this->weight += ($qty $t_properties_weight);

                    
    // attributes price
                    
    $attribute_price 0;
                    if(isset(
    $this->contents[$products_id]['attributes']))
                    {
                        
    reset($this->contents[$products_id]['attributes']);
                        while(list (
    $option$value) = each($this->contents[$products_id]['attributes']))
                        {
                            
    $values $xtPrice->xtcGetOptionPrice($product['products_id'], $option$value);

                            
    $this->weight += $values['weight'] * $qty;
                            
    $this->total += $values['price'] * $qty;
                            
    $attribute_price+=$values['price'];
                        }
                    }
                    
                    if(
    $product['products_tax_class_id'] != 0)
                    {
                        if(
    $_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1)
                        {
                            
    $products_price_tax $products_price - ($products_price 100 $_SESSION['customers_status']['customers_status_ot_discount']);
                            
    $attribute_price_tax $attribute_price - ($attribute_price 100 $_SESSION['customers_status']['customers_status_ot_discount']);
                        }

                        
    $products_tax $xtPrice->TAX[$product['products_tax_class_id']];
                        
    $products_tax_description xtc_get_tax_description($product['products_tax_class_id']);

                        
    // price incl tax
                        
    if($_SESSION['customers_status']['customers_status_show_price_tax'] == '1')
                        {
                            if(
    $_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1)
                            {
                                
    $this->tax[$product['products_tax_class_id']]['value'] += ((($products_price_tax $attribute_price_tax) / (100 $products_tax)) * $products_tax) * $qty;
                                
    $this->tax[$product['products_tax_class_id']]['desc'] = sprintf(TAX_INFO_INCL$products_tax '%');
                            }
                            else
                            {
                                
    $this->tax[$product['products_tax_class_id']]['value'] += ((($products_price $attribute_price) / (100 $products_tax)) * $products_tax) * $qty;
                                
    $this->tax[$product['products_tax_class_id']]['desc'] = sprintf(TAX_INFO_INCL$products_tax '%');
                            }
                        }

                        
    // excl tax + tax at checkout
                        
    if($_SESSION['customers_status']['customers_status_show_price_tax'] == && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1)
                        {
                            if(
    $_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1)
                            {
                                
    $this->tax[$product['products_tax_class_id']]['value'] += (($products_price_tax $attribute_price_tax) / 100) * ($products_tax) * $qty;
                                
    $this->total+=(($products_price_tax $attribute_price_tax) / 100) * ($products_tax) * $qty;
                                
    $this->tax[$product['products_tax_class_id']]['desc'] = sprintf(TAX_INFO_EXCL$products_tax '%');
                            }
                            else
                            {
                                
    $this->tax[$product['products_tax_class_id']]['value'] += (($products_price $attribute_price) / 100) * ($products_tax) * $qty;
                                
    $this->total+= (($products_price $attribute_price) / 100) * ($products_tax) * $qty;
                                
    $this->tax[$product['products_tax_class_id']]['desc'] = sprintf(TAX_INFO_EXCL$products_tax '%');
                            }
                        }
                    }

                    
    // round total value and total tax to avoid rounding problems if quantity is not an integer
                    
    if($qty != (int)$qty)
                    {
                        foreach(
    $this->tax as $t_tax_class_id => $t_content_array)
                        {
                            
    $this->tax[$t_tax_class_id]['value'] = round($this->tax[$t_tax_class_id]['value'], 2);
                        }

                        
    $this->total round($this->total2);
                    }
                }
            }
        }
     
  4. MBJ
    MBJ Aktives Mitglied
    Registriert seit:
    31. Januar 2012
    Beiträge:
    43
    Danke erhalten:
    3
    Danke vergeben:
    10
    Ist es denn generell möglich die "includes/classes/shopping_cart.php" mit "user_classes/overloads/shopping_cart/meineklasse.inc.php" zu überladen? Wie gesagt habe ich vor die Methode "calculate" zu überladen, aber selbst enfache print_r Tests geben nichts aus. Wenn ich die Klasse beim definieren absichtlich falsch schreibe, bekomme ich auch keine Fehlermeldung!
     
  5. Anonymous
    Anonymous Erfahrener Benutzer
    Mitarbeiter
    Registriert seit:
    22. Juni 2011
    Beiträge:
    4.760
    Danke erhalten:
    1.749
    Danke vergeben:
    137
    Hallo,

    der Name des Verzeichnisses in user_classes richtet sich nach dem Namen der zu überladenden Klasse, nicht nach dem Namen der Datei, in der die Origin-Klasse deklariert wird. Also in diesem Fall müsste ein Overload z.B. in user_classes/overloads/shoppingCart/MyShoppingCart.inc.php stecken.
     
  6. MBJ
    MBJ Aktives Mitglied
    Registriert seit:
    31. Januar 2012
    Beiträge:
    43
    Danke erhalten:
    3
    Danke vergeben:
    10
    Das war das winzige Detail, welches ich nicht gewusst habe. Ich dachte der Dateiname ist ausschlaggebend. Natürlich ist der Klassenname wichtig.
    Vielen, vielen Dank!