Jump to content

Minimun order category.


Antonio61

Recommended Posts

  • 6 months later...
  • 2 weeks later...

Hi there,

I have made a modification to get minimum order for one of a category...

I copy and modify the function getOrderTotal located in classes/Cart.php

Here you have new function, past it in Cart.php

/* Get category cart total */
       public function getCatOrderTotal($withTaxes = true, $type = 3, $cat)
   {
       if (!$this->id)
           return 0;
       $type = intval($type);
       if (!in_array($type, array(1, 2, 3, 4, 5, 6, 7)))
           die(Tools::displayError());

       // no shipping cost if is a cart with only virtuals products
       $virtual = $this->isVirtualCart();
       if ($virtual AND $type == 5)
           return 0;
       if ($virtual AND $type == 3)
           $type = 4;
       $shipping_fees = ($type != 4 AND $type != 7) ? $this->getOrderShippingCost(NULL, intval($withTaxes)) : 0;
       if ($type == 7)
           $type = 1;

       $products = $this->getProducts();
       $order_total = 0;
       if (Tax::excludeTaxeOption())
           $withTaxes = false;
       foreach ($products AS $product)
       {
                   //var_dump($product);
                   $category = new Category( intval($product['id_category_default']), intval($cookie->id_lang) );
                   //echo $category->id_parent;
                   if($category->id_parent == $cat){
           if ($this->_taxCalculationMethod == PS_TAX_EXC)
           {
               // Here taxes are computed only once the quantity has been applied to the product price
               $price = Product::getPriceStatic(intval($product['id_product']), false, intval($product['id_product_attribute']), 2, NULL, false, true, $product['cart_quantity'], false, (intval($this->id_customer) ? intval($this->id_customer) : NULL), intval($this->id), (intval($this->id_address_delivery) ? intval($this->id_address_delivery) : NULL));
               $total_price = $price * intval($product['cart_quantity']);
               if ($withTaxes)
                   $total_price = Tools::ps_round($total_price * (1 + floatval(Tax::getApplicableTax(intval($product['id_tax']), floatval($product['rate']))) / 100), 2);
           }
           else
           {
               $price = Product::getPriceStatic(intval($product['id_product']), $withTaxes, intval($product['id_product_attribute']), 6, NULL, false, true, $product['cart_quantity'], false, (intval($this->id_customer) ? intval($this->id_customer) : NULL), intval($this->id), (intval($this->id_address_delivery) ? intval($this->id_address_delivery) : NULL));
               if (!$withTaxes)
                   $total_price = Tools::ps_round($price * intval($product['cart_quantity']), 2);
               else
                   $total_price = Tools::ps_round($price, 2) * intval($product['cart_quantity']);
           }
           $order_total += $total_price;
                   }
       }
       $order_total_products = $order_total;
       if ($type == 2)
           $order_total = 0;
       // Wrapping Fees
       $wrapping_fees = 0;
       if ($this->gift)
       {
           $wrapping_fees = floatval(Configuration::get('PS_GIFT_WRAPPING_PRICE'));
           if ($withTaxes)
           {
               $wrapping_fees_tax = new Tax(intval(Configuration::get('PS_GIFT_WRAPPING_TAX')));
               $wrapping_fees *= 1 + ((floatval($wrapping_fees_tax->rate) / 100));
           }
           $wrapping_fees = Tools::convertPrice(Tools::ps_round($wrapping_fees, 2), new Currency(intval($this->id_currency)));
       }

       if ($type != 1)
       {
           $discounts = array();
           /* Firstly get all discounts, looking for a free shipping one (in order to substract shipping fees to the total amount) */
           if ($discountIds = $this->getDiscounts(true))
           {
               foreach ($discountIds AS $id_discount)
               {
                   $discount = new Discount(intval($id_discount['id_discount']));
                   if (Validate::isLoadedObject($discount))
                   {
                       $discounts[] = $discount;
                       if ($discount->id_discount_type == 3)
                           foreach($products AS $product)
                           {
                               $categories = Discount::getCategories($discount->id);
                               if (count($categories) AND Product::idIsOnCategoryId($product['id_product'], $categories))
                               {
                                   if($type == 2)
                                       $order_total -= $shipping_fees;
                                   $shipping_fees = 0;
                                   break;
                               }
                           }
                   }
               }
               /* Secondly applying all vouchers to the correct amount */
               foreach ($discounts AS $discount)
                   if ($discount->id_discount_type != 3)
                       $order_total -= Tools::ps_round(floatval($discount->getValue(sizeof($discounts), $order_total_products, $shipping_fees, $this->id, intval($withTaxes))), 2);
           }v
       }

       return Tools::ps_round(floatval($order_total), 2);
   }



Next you have to put this:

include_once(dirname(__FILE__).'/header.php');
       $total_inst = $cart->getCatOrderTotal(true, 5,3);
       if($total_inst < 60){
           echo '

               Message!!!!
';
       }


before

$smarty->display(_PS_THEME_DIR_.'shopping-cart.tpl'); 


In order.php

Numbre 3 is ID of category you want minimum order.
In my case I put minimum 60€

Link to comment
Share on other sites

This is complit condition with the style to prevent click on order button.

$total_inst = $cart->getCatOrderTotal(true, 5,3);
       if($total_inst < 60){
           echo '

               Lo sentimos, pero debido a los requisitos del provedor, pedído minimo en INSTRUMENTAL
               tiene que superar 60€. 


               Actualmente el total en instrumental es de: '.$total_inst.'€

               Faltan: '.(60-$total_inst).'€

           <style>
           p#cart-buttons a.exclusive, p.cart_navigation a.exclusive {
               display:none;}
           </style>
           ';
       }

Link to comment
Share on other sites

  • 5 months later...
  • 1 year later...
  • 6 years later...

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
×
×
  • Create New...