Jump to content
jpweber

Quantity Price Breaks

Recommended Posts

my issue is:

 

I installed Quantity Price Breaks contribution on one fresh osc2.2 RC1 and RC2a. When I put say a quantity of 8 in the shopping cart, it would not calculate the discount. The discount table shows up correctly on the product info page. After seeing that the discount was not being applied.

 

example:

Quantity 1+ 5+ 20+

Price for each $10.00 $9.00 $8.00

Your savings - 10% 20%

 

when buy 10 pcs, it still 10.00USD per pcs. total 100$.

I installed it this morning and you are right. It is not calculating the discount. From what I see it looks like it goes horribly wrong in includes/classes/shopping_cart.php in the function calculate because of the discount category code that was added (and things left out here and there). I think it happens only when a product is not added to a discount category but it shouldn't be obligatory to define discount categories for all products.

 

That will take time to sort out.

Share this post


Link to post
Share on other sites
I installed it this morning and you are right. It is not calculating the discount. From what I see it looks like it goes horribly wrong in includes/classes/shopping_cart.php in the function calculate because of the discount category code that was added (and things left out here and there). I think it happens only when a product is not added to a discount category but it shouldn't be obligatory to define discount categories for all products.

 

That will take time to sort out.

 

Very thanks for your testing.

yes, I don't added to a discount category now.

 

Best Regards,

Share this post


Link to post
Share on other sites

I have found a few people that have this problem that I am, but don't understand the answer for it to be fixed. First, amazing contribution, but I have this problem still with no clue on how to fix it.

 

The price breaks are combing in the shopping cart, which we would not like to happen. Say the price break for 50 is 27 and for 100 is 39 when buying one product and if you wanted to buy two sepearte products you would add the total of each product, not combine the amounts. For example, the customer is going to order productA that is 27 when buying 50, and they also want some of productB which is 27 for 50 as well but both products are or are not in the same category. single purchases work fine, but when two are combined, when it gets to the shopping cart instead of the total being 27+27=54, it is the price break for a product when ordering 100 - 39 (which is not a good sign for the store!).

 

I am searched and searched for an answer to this, can anyone point me in the right direction. Is this even possible? We deffinately want customers to be able to order more than one without a problem. Thanks in advance for any help.

Share this post


Link to post
Share on other sites
I have found a few people that have this problem that I am, but don't understand the answer for it to be fixed.

I don't know which version you are using, I guess 1.3.0 or 1.3.1? I can tell you that 1.3.1 is not working as it should.

Share this post


Link to post
Share on other sites
I can tell you that 1.3.1 is not working as it should.

I now made (sometimes quite major) changes to includes/classes/shopping_cart.php, includes/classes/PriceFormatter.php, includes/classes/PriceFormatterStore.php, includes/modules/product_listing.php, and product_info.php and I think it now works fine (without going back to the database structure of 1.2.9 and previous versions).

 

This version is now uploaded as version 1.3.2.

Edited by Jan Zonjee

Share this post


Link to post
Share on other sites
I now made (sometimes quite major) changes to includes/classes/shopping_cart.php, includes/classes/PriceFormatter.php, includes/classes/PriceFormatterStore.php, includes/modules/product_listing.php, and product_info.php and I think it now works fine (without going back to the database structure of 1.2.9 and previous versions).

 

This version is now uploaded as version 1.3.2.

 

Hi Jan:

Thanks you very much! You are best :)

 

Best Regards,

Share this post


Link to post
Share on other sites
I now made (sometimes quite major) changes to includes/classes/shopping_cart.php, includes/classes/PriceFormatter.php, includes/classes/PriceFormatterStore.php, includes/modules/product_listing.php, and product_info.php and I think it now works fine (without going back to the database structure of 1.2.9 and previous versions).

 

This version is now uploaded as version 1.3.2.

 

Hi Jan:

after setting okay from admin (not select Discount Catalog), when enter product selection : index.php?cPath=1_4, have following error:

 

Warning: Invalid argument supplied for foreach() in D:\Guojiang Fu\webserver\GApm\htdocs\osctest\includes\classes\PriceFormatter.php on line 117

 

Warning: Invalid argument supplied for foreach() in D:\Guojiang Fu\webserver\GApm\htdocs\osctest\includes\classes\PriceFormatter.php on line 129

 

 

Best Regards,

Share this post


Link to post
Share on other sites
after setting okay from admin (not select Discount Catalog), when enter product selection : index.php?cPath=1_4, have following error:

 

Warning: Invalid argument supplied for foreach() in D:\Guojiang Fu\webserver\GApm\htdocs\osctest\includes\classes\PriceFormatter.php on line 117

 

Warning: Invalid argument supplied for foreach() in D:\Guojiang Fu\webserver\GApm\htdocs\osctest\includes\classes\PriceFormatter.php on line 129

Is there a price break entered for the product you edited? Do you use PHP5 or PHP4 (might have nothing to do with it but I use PHP5)? Both errors have to do with "foreach" going over the array with price breaks.

 

Did you change includes/modules/product_listing.php? It looks like I forgot to replace that file in the package. I'll check it and if so, will upload a fresh one under the same name with an "a" appended and disable the previous one.

Share this post


Link to post
Share on other sites
Is there a price break entered for the product you edited? Do you use PHP5 or PHP4 (might have nothing to do with it but I use PHP5)? Both errors have to do with "foreach" going over the array with price breaks.

 

Did you change includes/modules/product_listing.php? It looks like I forgot to replace that file in the package. I'll check it and if so, will upload a fresh one under the same name with an "a" appended and disable the previous one.

 

Hi Jan:

yes, I have a price break entered for the product edited.

I use PHP5:

Server OS: Database:MySQL 5.0.27-community-nt-logServer Date:05/04/2008 08:57:39 Datebase Date:05/04/2008 16:57:38Server Up Time:pixel_trans.gifHTTP Server:Apache/2.0.59 (Win32) PHP/5.2.1PHP Version:5.2.1 (Zend: 2.2.0)

I don't change includes/modules/product_listing.php . I copy all catalog into my osc, my osc is fresh osc for testing.

 

It is normal display on example : product_info.php?cPath=2_19&products_id=22 ,

only have error on exmaple : /index.php?cPath=2_19

 

Best Regards,

Edited by sunrise99

Share this post


Link to post
Share on other sites
only have error on exmaple : /index.php?cPath=2_19

Sounds like the module product_listing.php. Did you try the version from 1.3.2a? Just uploaded it.

Share this post


Link to post
Share on other sites
Sounds like the module product_listing.php. Did you try the version from 1.3.2a? Just uploaded it.

 

This version work perfect, thanks!!!

 

BTW, did you update install.html file?

 

Thanks & Best Regards,

Share this post


Link to post
Share on other sites
This version work perfect, thanks!!!

Good

BTW, did you update install.html file?

Of course, otherwise this thread would get inundated with posts :)

 

But I must admit I haven't checked the new install instructions by starting with a fresh file and see if following the instructions would give the expected result. I'm gambling there I didn't mess up ;)

Share this post


Link to post
Share on other sites

Jan and all,

 

Found a typo in the new upload of 1.3.2a

In catalog/includes/classes/shopping_cart.php

 

find on line 298:

$products_price = $pf->computePrice($qty, $no_of_other_items_in_cart_from_same_cat);

 

and replace with:

$products_price = $pf->computePrice($qty, $nof_other_items_in_cart_same_cat);

 

 

This typo was causing the subtotal to calculate incorrectly in the shopping cart with using category discount quantities.

 

Greg


I only do what my Rice Krispies tell me to do!

Share this post


Link to post
Share on other sites
Jan and all,

 

Found a typo in the new upload of 1.3.2a

In catalog/includes/classes/shopping_cart.php

Oops :blush:

 

Fixed it in version 1.3.2b as of now.

 

Thanks Greg :thumbsup:

Share this post


Link to post
Share on other sites
Oops :blush:

 

Fixed it in version 1.3.2b as of now.

 

Thanks Greg :thumbsup:

 

Your welcome my friend!!! :D


I only do what my Rice Krispies tell me to do!

Share this post


Link to post
Share on other sites

I have installed this contribution, all what I have done was replacing the files from the contribution with a fresh install; I'm having the following problem:

1- In the catalog page when I view my category (x) product page, I see the prices are all missed up. For one of my products I see the price have changed to the lowest price in the quantity price break table, and for other products if i make a purchase I see the price in the same 'product category listing page' to be the following: on sale $0.00 and above it another zero dollar value which is crossed out.

 

If I select a product, in the shopping cart I see the accurate money value for the product

 

Thanks for this wonderful contribution

Edited by mockba

Share this post


Link to post
Share on other sites

this is just a suggestion for this contribution which i love very much. I was wondering if it's possible to make it so you can type in "Call for pricing" when the quantity is above a certain amount such as 1000 units. I have no idea how it would be done, but that would be a nice feature to add to this contribution.

 

I would like to let my customers know that for extremely large quantities, that we can negotiate the price more, but that i would like to talk to them about the sale.

Share this post


Link to post
Share on other sites

mockba,

 

Which version of OSC are you using? Sounds like you didn't copy/replace all of the files or your using a different version of OSC than what the latest release of this contrib is designed around


I only do what my Rice Krispies tell me to do!

Share this post


Link to post
Share on other sites
I now made (sometimes quite major) changes to includes/classes/shopping_cart.php, includes/classes/PriceFormatter.php, includes/classes/PriceFormatterStore.php, includes/modules/product_listing.php, and product_info.php and I think it now works fine (without going back to the database structure of 1.2.9 and previous versions).

 

This version is now uploaded as version 1.3.2.

 

Jan,

Thanks so much for making these updates, and so quickly!! I went through as best I could to update what I already had, with other contributions as well, to make the edits to the pages that you mentioned and I am now getting this error, and am not sure where to go, I tried to match everything up perfectly, but I know I probably missed something. Have any ideas of where the fix could be?

 

Fatal error: Call to a member function getPriceFormatterData() on a non-object in /var/www/html/catalog/includes/classes/shopping_cart.php on line 402

 

This is a few lines of my code, can you see any errors:

 

// BOF qpbpp
       $discount_category_quantity = array(); // calculates no of items per discount category in shopping basket
     foreach ($this->contents as $products_id => $contents_array) {
      if (!isset($discount_category_quantity[$contents_array['discount_categories_id']])) {
	      $discount_category_quantity[$contents_array['discount_categories_id']] = $contents_array['qty'];
      } else {
	      $discount_category_quantity[$contents_array['discount_categories_id']] += $contents_array['qty'];
      }
     } // end foreach

  $pf = new PriceFormatter;
// EOF qpbpp
// BOF qpbpp
       $discount_category_quantity = array(); // calculates no of items per discount category in shopping basket
     foreach ($this->contents as $products_id => $contents_array) {
      if (!isset($discount_category_quantity[$contents_array['discount_categories_id']])) {
	      $discount_category_quantity[$contents_array['discount_categories_id']] = $contents_array['qty'];
      } else {
	      $discount_category_quantity[$contents_array['discount_categories_id']] += $contents_array['qty'];
      }
     } // end foreach

  $pf = new PriceFormatter;
// EOF qpbpp

     // BOF qpbpp        
     if (tep_not_null($this->contents[$products_id]['discount_categories_id'])) {
       $nof_items_in_cart_same_cat = $discount_category_quantity[$this->contents[$products_id]['discount_categories_id']];
       $nof_other_items_in_cart_same_cat = $nof_items_in_cart_same_cat - $qty;
     } else {
         $nof_other_items_in_cart_same_cat = 0;
     }
// EOF qpbpp

// products price
      /* // BOF qpbpp
       $nof_items_in_cart_same_cat = $discount_category_quantity[$this->contents[$products_id]['discount_categories_id']];
       $nof_other_items_in_cart_same_cat = $nof_items_in_cart_same_cat - $qty; */

       //$product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
       $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight, products_qty_blocks from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
       if ($product = tep_db_fetch_array($product_query)) {

	  // BOF qpbpp
      $pf->loadProduct($products_id, $languages_id);
       if ($product = $pfs->getPriceFormatterData($products_id)) {
         $prid = $product['products_id'];
         $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
         $products_price = $pf->computePrice($qty, $nof_items_in_cart_same_cat);
// EOF qpbpp
         //$products_price = $product['products_price'];

// EOF qpbpp
         $products_weight = $product['products_weight'];

         // BOF qpbpp
         /*
         $specials_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_query)) {
           $specials = tep_db_fetch_array($specials_query);
           $products_price = $specials['specials_new_products_price'];
         }
         */
// EOF qpbpp

         $this->total += tep_add_tax($products_price, $products_tax) * $qty;
         $this->weight += ($qty * $products_weight);
       }

// attributes price
       if (isset($this->contents[$products_id]['attributes'])) {
         reset($this->contents[$products_id]['attributes']);
         while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
           $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
           $attribute_price = tep_db_fetch_array($attribute_price_query);
           if ($attribute_price['price_prefix'] == '+') {
             $this->total += $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
           } else {
             $this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
           }
         }
       }
     }
   }

   function attributes_price($products_id) {
     $attributes_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'])) {
         $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
         $attribute_price = tep_db_fetch_array($attribute_price_query);
         if ($attribute_price['price_prefix'] == '+') {
           $attributes_price += $attribute_price['options_values_price'];
         } else {
           $attributes_price -= $attribute_price['options_values_price'];
         }
       }
     }

     return $attributes_price;
   }

   function get_products() {
     global $languages_id, $pfs;

     if (!is_array($this->contents)) return false;

 // BOF qpbpp
     $discount_category_quantity = array();
     foreach ($this->contents as $products_id => $contents_array) {
      if(tep_not_null($contents_array['discount_categories_id'])) {
        if (!isset($discount_category_quantity[$contents_array['discount_categories_id']])) {
	        $discount_category_quantity[$contents_array['discount_categories_id']] = $contents_array['qty'];
        } else {
	        $discount_category_quantity[$contents_array['discount_categories_id']] += $contents_array['qty'];
        }
      }
     } // end foreach

     $pf = new PriceFormatter;
// EOF qpbpp

     $products_array = array();
     reset($this->contents);
     while (list($products_id, ) = each($this->contents)) {
// BOF qpbpp
     $pf->loadProduct($products_id, $languages_id); // does query if necessary and adds to 
     // PriceFormatterStore or gets info from it next
  if ($products = $pfs->getPriceFormatterData($products_id)) {
      if (tep_not_null($this->contents[$products_id]['discount_categories_id'])) {
         $nof_items_in_cart_same_cat =  $discount_category_quantity[$this->contents[$products_id]['discount_categories_id']];
         $nof_other_items_in_cart_same_cat = $nof_items_in_cart_same_cat - $this->contents[$products_id]['qty'];
       } else {
         $nof_other_items_in_cart_same_cat = 0;
       }
         $products_price = $pf->computePrice($this->contents[$products_id]['qty'], $nof_other_items_in_cart_same_cat);
// EOF qpbpp

         $products_array[] = array('id' => $products_id,
                                   'name' => $products['products_name'],
                                   'model' => $products['products_model'],
                                   'image' => $products['products_image'],
// BOF qpbpp
			    'discount_categories_id' => $this->contents[$products_id]['discount_categories_id'],
// EOF qpbpp
       /*// BOF qpbpp
       //$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
       $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id, p.products_qty_blocks from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
       if ($products = tep_db_fetch_array($products_query)) {
         /*
         $prid = $products['products_id'];
         $products_price = $products['products_price'];

         $specials_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_query)) {
           $specials = tep_db_fetch_array($specials_query);
           $products_price = $specials['specials_new_products_price'];
         }


         $pf->loadProduct($products['products_id'], $products['products_price'], $products['products_tax_class_id'], (int)$products['products_qty_blocks']);
         $nof_items_in_cart_same_cat =  $discount_category_quantity[$this->contents[$products_id]['discount_categories_id']];
         $nof_other_items_in_cart_same_cat = $nof_items_in_cart_same_cat - $this->contents[$products_id]['qty'];
         $products_price = $pf->computePrice($this->contents[$products_id]['qty'], $nof_other_items_in_cart_same_cat);
// EOF qpbpp */

                                   'price' => $products_price,
                                   'quantity' => $this->contents[$products_id]['qty'],
                                   'weight' => $products['products_weight'],
                                   'final_price' => ($products_price + $this->attributes_price($products_id)),
                                   'tax_class_id' => $products['products_tax_class_id'],
// BOF Product Type Option
                                   //'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));
                                   'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''),
                                   'attributes_values' => (isset($this->contents[$products_id]['attributes_values']) ? $this->contents[$products_id]['attributes_values'] : ''));
// EOF Product Type Option

 

Please let me know. Thank you for all of your help.

Share this post


Link to post
Share on other sites
Fatal error: Call to a member function getPriceFormatterData() on a non-object in /var/www/html/catalog/includes/classes/shopping_cart.php on line 402

 

This is a few lines of my code, can you see any errors:

I can't see what your line 402 is, so that is a bit searching for a needle in a haystack. It sounds like $pfs not being available to the function where this line is in. In the functions you will find as one of the first lines the global declaration. $pfs is on them if it is needed.

Share this post


Link to post
Share on other sites
I can't see what your line 402 is, so that is a bit searching for a needle in a haystack. It sounds like $pfs not being available to the function where this line is in. In the functions you will find as one of the first lines the global declaration. $pfs is on them if it is needed.

 

Here are some of the line numbers, I kind of forgot about that aspect, sorry. I have it exactly like your file in the download so I am not sure what is not available. Where would I find the functions tos ee if it is needed?

 

400 // BOF qpbpp
      401$pf->loadProduct($products_id, $languages_id);
      402 if ($product = $pfs->getPriceFormatterData($products_id)) {
        403 $prid = $product['products_id'];
         404 $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
         405 $products_price = $pf->computePrice($qty, $nof_items_in_cart_same_cat);
406 // EOF qpbpp

Share this post


Link to post
Share on other sites
Here are some of the line numbers, I kind of forgot about that aspect, sorry. I have it exactly like your file in the download so I am not sure what is not available.

Like this?

	function get_products() {
  global $languages_id, $pfs;

You also made the changed in includes/application_top.php?

// include currencies class and create an instance
 require(DIR_WS_CLASSES . 'currencies.php');
 $currencies = new currencies();
// BOF qpbpp
 // include the price formatter classes for the price breaks contribution
 require(DIR_WS_CLASSES . 'PriceFormatter.php');
 $pf = new PriceFormatter;
 require(DIR_WS_CLASSES . 'PriceFormatterStore.php');
 $pfs = new PriceFormatterStore;
// EOF qpbpp

// include the mail classes

Share this post


Link to post
Share on other sites
mockba,

 

Which version of OSC are you using? Sounds like you didn't copy\replace all of the files or your using a different version of OSC than what the latest release of this contrib is designed around

 

I'm using osCommerce Online Merchant v2.2 RC2, and I made sure that I did copy replace all files as I copied the catalog directory from the contribution as is and I replaced the files in the catalog, as I said I had a fresh install, I'm double checking again, I will inform you if works or not

 

Thanks

Share this post


Link to post
Share on other sites

I have double checked it, I'm not sure wither the contribution is the cause of the error or not, but this error appeared after I have added the contribution.

The main problem is related to displaying accurate price values for my products in the categories page. Once I have installed the contribution and created the discount levels, the current price I see for each product is the lowest in the table and it says "From $54" which is the lowest fare for one of my products if quantity is greater than 101+. Up to this point everything is fine.

Now when I select an item and make a purchase, problems start. When I return back to my category's page, product(s) that I have purchased earlier will have the following "From $0" displayed in the price. The $0 disappears if I select a product to purchase by clicking the "Buy now" button then from the "Whats on my cart Page" I click on the "Continue Shopping" Prices appear normally once again.

 

I guess the problem is related to updating the price value of the product in the category's view page!

If you could assist me on how to fix this problem

Edited by mockba

Share this post


Link to post
Share on other sites
Now when I select an item and make a purchase, problems start. When I return back to my category's page, product(s) that I have purchased earlier will have the following "From $0" displayed in the price. The $0 disappears if I select a product to purchase by clicking the "Buy now" button then from the "Whats on my cart Page" I click on the "Continue Shopping" Prices appear normally once again.

Perhaps you didn't change the class PriceFormatterStore.php?

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

×