Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

buy x items get the cheapest for free


fruchtge

Recommended Posts

Hi, I like to have the option buy x items get the cheapest for free in my shop. I like to change the $products_price variable in function calculate() und function get_products() of includes/classes/shopping_cart.php with this code (now it is basic and just an idea)

 

 if ( ($this->count_contents() > 3) && ($products_id == $this->cheapestproduct())) { $products_price = '0'; }

 

my Problem is to get the cheapest item in cart, my function cheapestproduct() does not work:

 



   function cheapestproduct() {

     if (is_array($this->contents)) {
       reset($this->contents);
       while (list($products_id, ) = each($this->contents)) {


         $product_special_query = tep_db_query("select products_id, products_price from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
         if ($product_special = tep_db_fetch_array($product_special_query)) {
           $pr_special_id = $product_special['products_id'];
           $products_special_price = $product_special['products_price'];

           $specials_special_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
           if (tep_db_num_rows ($specials_special_query)) {
             $specials_special = tep_db_fetch_array($specials_special_query);
             $products_special_price = $specials_special['specials_new_products_price'];
           }
//            $this->total += $currencies->calculate_price($products_price, $products_tax, $qty);
//            $this->weight += ($qty * $products_weight);
         }

         if (tep_not_null($cheapestproduct)) {
           if ($products_special_price < $cheapestprice) {
             $cheapestproduct = $products_id;
             $cheapestprice = $products_special_price;
           } else {

           }

         } else {
         $cheapestproduct = $products_id;
         $cheapestprice = $products_special_price;
         }
       }
     }
     return $cheapestproduct;
   }



 

Maybe someone could help.

life long and knusper

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...