Jump to content

Error during instal module with override


se1989rg
 Share

Recommended Posts

Hi!

I developed module with cart class override. Prestashop version 1.6.0.11.
During iinstallation show message:

 

pmsmartorder : 

   Unable to install override:: Class CartOverride54e325e089b4e does not exist.

 

I deleted file class_index.php, but this didn't help.

my Cart class placed in modules/my_module/override/clasess/Cart.php

This is my Class
 

<?php

class Cart extends CartCore {
    
    
    public function getOrderTotal($with_taxes = true, $type = Cart::BOTH, $products = null, $id_carrier = null, $use_cache = true)
            {
                    static $address = null;

                    if (!$this->id)
                            return 0;

                    $type = (int)$type;
                    $array_type = array(
                            Cart::ONLY_PRODUCTS,
                            Cart::ONLY_DISCOUNTS,
                            Cart::BOTH,
                            Cart::BOTH_WITHOUT_SHIPPING,
                            Cart::ONLY_SHIPPING,
                            Cart::ONLY_WRAPPING,
                            Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING,
                            Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING,
                    );

                    // Define virtual context to prevent case where the cart is not the in the global context
                    $virtual_context = Context::getContext()->cloneContext();
                    $virtual_context->cart = $this;

                    if (!in_array($type, $array_type))
                            die(Tools::displayError());

                    $with_shipping = in_array($type, array(Cart::BOTH, Cart::ONLY_SHIPPING));

                    // if cart rules are not used
                    if ($type == Cart::ONLY_DISCOUNTS && !CartRule::isFeatureActive())
                            return 0;

                    // no shipping cost if is a cart with only virtuals products
                    $virtual = $this->isVirtualCart();
                    if ($virtual && $type == Cart::ONLY_SHIPPING)
                            return 0;

                    if ($virtual && $type == Cart::BOTH)
                            $type = Cart::BOTH_WITHOUT_SHIPPING;

                    if ($with_shipping || $type == Cart::ONLY_DISCOUNTS)
                    {
                            if (is_null($products) && is_null($id_carrier))
                                    $shipping_fees = $this->getTotalShippingCost(null, (boolean)$with_taxes);
                            else
                                    $shipping_fees = $this->getPackageShippingCost($id_carrier, (bool)$with_taxes, null, $products);
                    }
                    else
                            $shipping_fees = 0;

                    if ($type == Cart::ONLY_SHIPPING)
                            return $shipping_fees;

                    if ($type == Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING)
                            $type = Cart::ONLY_PRODUCTS;

                    $param_product = true;
                    if (is_null($products))
                    {
                            $param_product = false;
                            $products = $this->getProducts();
                    }

                    if ($type == Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING)
                    {
                            foreach ($products as $key => $product)
                                    if ($product['is_virtual'])
                                            unset($products[$key]);
                            $type = Cart::ONLY_PRODUCTS;
                    }

                    $order_total = 0;
                    if (Tax::excludeTaxeOption())
                            $with_taxes = false;

                    $products_total = array();
                    $ecotax_total = 0;

                    foreach ($products as $product) // products refer to the cart details
                    {
                            if ($virtual_context->shop->id != $product['id_shop'])
                                    $virtual_context->shop = new Shop((int)$product['id_shop']);

                            if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice')
                                    $id_address = (int)$this->id_address_invoice;
                            else
                                    $id_address = (int)$product['id_address_delivery']; // Get delivery address of the product from the cart
                            if (!Address::addressExists($id_address))
                                    $id_address = null;

                            $price = Product::getPriceStatic(
                                    (int)$product['id_product'],
                                    false,
                                    (int)$product['id_product_attribute'],
                                    6,
                                    null,
                                    false,
                                    true,
                                    $product['cart_quantity'],
                                    false,
                                    (int)$this->id_customer ? (int)$this->id_customer : null,
                                    (int)$this->id,
                                    $id_address,
                                    $null,
                                    false,
                                    true,
                                    $virtual_context
                            );

                            if (Configuration::get('PS_USE_ECOTAX'))
                            {
                                    $ecotax = $product['ecotax'];
                                    if (isset($product['attribute_ecotax']) && $product['attribute_ecotax'] > 0)
                                            $ecotax = $product['attribute_ecotax'];
                            }
                            else
                                    $ecotax = 0;

                            $address = Address::initialize($id_address, true);

                            if ($with_taxes)
                            {
                                    $id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int)$product['id_product'], $virtual_context);
                                    $tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator();

                                    if ($ecotax)
                                            $ecotax_tax_calculator = TaxManagerFactory::getManager($address, (int)Configuration::get('PS_ECOTAX_TAX_RULES_GROUP_ID'))->getTaxCalculator();
                            }
                            else
                                    $id_tax_rules_group = 0;

                            if (in_array(Configuration::get('PS_ROUND_TYPE'), array(Order::ROUND_ITEM, Order::ROUND_LINE)))
                            {
                                    if (!isset($products_total[$id_tax_rules_group]))
                                            $products_total[$id_tax_rules_group] = 0;
                            }
                            else
                                    if (!isset($products_total[$id_tax_rules_group.'_'.$id_address]))
                                            $products_total[$id_tax_rules_group.'_'.$id_address] = 0;

                            switch (Configuration::get('PS_ROUND_TYPE'))
                            {
                                    case Order::ROUND_TOTAL:
                                            $products_total[$id_tax_rules_group.'_'.$id_address] += $price * (int)$product['cart_quantity'];

                                            if ($ecotax)
                                                    $ecotax_total += $ecotax * (int)$product['cart_quantity'];
                                            break;
                                    case Order::ROUND_LINE:
                                            $product_price = $price * $product['cart_quantity'];
                                            $products_total[$id_tax_rules_group] += Tools::ps_round($product_price, _PS_PRICE_COMPUTE_PRECISION_);

                                            if ($with_taxes)
                                                    $products_total[$id_tax_rules_group] += Tools::ps_round($tax_calculator->getTaxesTotalAmount($product_price), _PS_PRICE_COMPUTE_PRECISION_);

                                            if ($ecotax)
                                            {
                                                    $ecotax_price = $ecotax * (int)$product['cart_quantity'];
                                                    $ecotax_total += Tools::ps_round($ecotax_price, _PS_PRICE_COMPUTE_PRECISION_);

                                                    if ($with_taxes)
                                                            $ecotax_total += Tools::ps_round($ecotax_tax_calculator->getTaxesTotalAmount($ecotax_price), _PS_PRICE_COMPUTE_PRECISION_);
                                            }
                                            break;
                                    case Order::ROUND_ITEM:
                                    default:
                                            $product_price = $with_taxes ? $tax_calculator->addTaxes($price) : $price;
                                            $products_total[$id_tax_rules_group] += Tools::ps_round($product_price, _PS_PRICE_COMPUTE_PRECISION_) * (int)$product['cart_quantity'];

                                            if ($ecotax)
                                            {
                                                    $ecotax_price = $with_taxes ? $ecotax_tax_calculator->addTaxes($ecotax) : $ecotax;
                                                    $ecotax_total += Tools::ps_round($ecotax_price, _PS_PRICE_COMPUTE_PRECISION_) * (int)$product['cart_quantity'];
                                            }
                                            break;
                            }
                    }

                    foreach ($products_total as $key => $price)
                    {
                            if ($with_taxes && Configuration::get('PS_ROUND_TYPE') == Order::ROUND_TOTAL)
                            {
                                    $tmp = explode('_', $key);
                                    $address = Address::initialize((int)$tmp[1], true);
                                    $tax_calculator = TaxManagerFactory::getManager($address, $tmp[0])->getTaxCalculator();
                                    $order_total += Tools::ps_round($price, _PS_PRICE_COMPUTE_PRECISION_) + Tools::ps_round($tax_calculator->getTaxesTotalAmount($price), _PS_PRICE_COMPUTE_PRECISION_);
                            }
                            else
                                    $order_total += $price;
                    }

                    if ($ecotax_total && $with_taxes && Configuration::get('PS_ROUND_TYPE') == Order::ROUND_TOTAL)
                            $ecotax_total = Tools::ps_round($ecotax_total, _PS_PRICE_COMPUTE_PRECISION_) + Tools::ps_round($ecotax_tax_calculator->getTaxesTotalAmount($ecotax_total), _PS_PRICE_COMPUTE_PRECISION_);

                    $order_total += $ecotax_total;
                    $order_total_products = $order_total;

                    if ($type == Cart::ONLY_DISCOUNTS)
                            $order_total = 0;

                    // Wrapping Fees
                    $wrapping_fees = 0;
                    if ($this->gift)
                            $wrapping_fees = Tools::convertPrice(Tools::ps_round($this->getGiftWrappingPrice($with_taxes), _PS_PRICE_COMPUTE_PRECISION_), Currency::getCurrencyInstance((int)$this->id_currency));
                    if ($type == Cart::ONLY_WRAPPING)
                            return $wrapping_fees;

                    $order_total_discount = 0;
                    if (!in_array($type, array(Cart::ONLY_SHIPPING, Cart::ONLY_PRODUCTS)) && CartRule::isFeatureActive())
                    {
                            // First, retrieve the cart rules associated to this "getOrderTotal"
                            if ($with_shipping || $type == Cart::ONLY_DISCOUNTS)
                                    $cart_rules = $this->getCartRules(CartRule::FILTER_ACTION_ALL);
                            else
                            {
                                    $cart_rules = $this->getCartRules(CartRule::FILTER_ACTION_REDUCTION);
                                    // Cart Rules array are merged manually in order to avoid doubles
                                    foreach ($this->getCartRules(CartRule::FILTER_ACTION_GIFT) as $tmp_cart_rule)
                                    {
                                            $flag = false;
                                            foreach ($cart_rules as $cart_rule)
                                                    if ($tmp_cart_rule['id_cart_rule'] == $cart_rule['id_cart_rule'])
                                                            $flag = true;
                                            if (!$flag)
                                                    $cart_rules[] = $tmp_cart_rule;
                                    }
                            }

                            $id_address_delivery = 0;
                            if (isset($products[0]))
                                    $id_address_delivery = (is_null($products) ? $this->id_address_delivery : $products[0]['id_address_delivery']);
                            $package = array('id_carrier' => $id_carrier, 'id_address' => $id_address_delivery, 'products' => $products);

                            // Then, calculate the contextual value for each one
                            foreach ($cart_rules as $cart_rule)
                            {
                                    // If the cart rule offers free shipping, add the shipping cost
                                    if (($with_shipping || $type == Cart::ONLY_DISCOUNTS) && $cart_rule['obj']->free_shipping)
                                            $order_total_discount += Tools::ps_round($cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_SHIPPING, ($param_product ? $package : null), $use_cache), _PS_PRICE_COMPUTE_PRECISION_);

                                    // If the cart rule is a free gift, then add the free gift value only if the gift is in this package
                                    if ((int)$cart_rule['obj']->gift_product)
                                    {
                                            $in_order = false;
                                            if (is_null($products))
                                                    $in_order = true;
                                            else
                                                    foreach ($products as $product)
                                                            if ($cart_rule['obj']->gift_product == $product['id_product'] && $cart_rule['obj']->gift_product_attribute == $product['id_product_attribute'])
                                                                    $in_order = true;

                                            if ($in_order)
                                                    $order_total_discount += $cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_GIFT, $package, $use_cache);
                                    }

                                    // If the cart rule offers a reduction, the amount is prorated (with the products in the package)
                                    if ($cart_rule['obj']->reduction_percent > 0 || $cart_rule['obj']->reduction_amount > 0)
                                            $order_total_discount += Tools::ps_round($cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_REDUCTION, $package, $use_cache), _PS_PRICE_COMPUTE_PRECISION_);
                            }
                            $order_total_discount = min(Tools::ps_round($order_total_discount, 2), $wrapping_fees + $order_total_products + $shipping_fees);
                            $order_total -= $order_total_discount;
                    }

                    if ($type == Cart::BOTH)
                            $order_total += $shipping_fees + $wrapping_fees;

                    if ($order_total < 0 && $type != Cart::ONLY_DISCOUNTS)
                            return 0;

                    if ($type == Cart::ONLY_DISCOUNTS)
                            return $order_total_discount;

                    $payment_discount = Tools::getValue('payment_discount');

                    if($payment_discount !=0 ) {

                        $order_total = ($order_total*$payment_discount)/100;

                        setcookie ("payment_discount", $payment_discount,time()+3600);
                    } else if($payment_discount === '0' ){
                        unset($_COOKIE['payment_discount']);
                        setcookie('payment_discount', null, -1, '/');
                    } else if ($_COOKIE['payment_discount']){
                        $order_total = ($order_total*$_COOKIE['payment_discount'])/100;
                    }
    
                    return Tools::ps_round((float)$order_total, _PS_PRICE_COMPUTE_PRECISION_);
            }
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More