Jump to content

Quantity Discount not working 'correctly'


YnZs

Recommended Posts

So i just upgraded to CC5.1.4, using skin "Mauris"

 

I have a particular product that i sell for $0.75 for 1, i tried to setup the quantity discount so if the customer buys 100+ the price changes to $0.60

what happens, is that it changes the price to $.60 once the quantity goes over 50+! If i change the option to 200+ then the cart changes the price once

it goes over 100+

 

One particular thing I've noticed, is that when i Delete the Quantity/Price discount option, a window pops up, all it says it "Undefined" with either "ok" or "Cancel"

now that i think about it, i've never hit "Cancel" ... either way, it Deletes the option, and the option shows up and deletes from the products page correctly, but the

'math' is off i guess, it gives the discount with too little of a quantity.

 

I couldn't find anything in this forum about it, or anyone else having the same problem

Link to comment
Share on other sites

Welcome YnZs! Glad to see you made it to the forums.

 

I won't try to find the problem with the odd message box, as CC514 is too old of a version. Current is CC521.

 

But the quantity price discount does have a bug in CC52X. I do not know if/where a bug would be for CC514.

 

Are you sure you have CC514?

Link to comment
Share on other sites

Well thank you sir, I've been reading these forums for awhile and have managed to find a fix for any little issue I've ever come across, except this one.

 

After reading quite a few posts i KNEW it was detrimental to a solution to find and post the exact version that i am using,

I use "Bluehost" as my ISP provider, their "Simplescripts" installs have me listed as having 5.1.4, though now i'm starting

to second guess myself, I had issues trying to manually upgrade, i contacted CC customer support and basically gave

them all my log-in info and they fixed it for me.

 

Is there any other way to find out?

Link to comment
Share on other sites

Using that image as a guide, directly under the series of tabs (Backup, Upgrade, etc) is the Breadcrumb list. The first item of all breadcrumbs is Dashboard. This is what you see when you first login as admin. Click on the word, Dashboard.

 

On the Dashboard page, click the Store Overview tab.

Link to comment
Share on other sites

CubeCart fixed my installation issues, not the quantity discount issue, that's why i was saying i was confused as to what version of CC i was using, because THEY installed it, not me, and under Bluehosts "Simple Scripts" it shows me i have....

Installs.JPG

 

But as the image in my post above shows (store overview), i have something else, and i can't "Update" SimpleS to say anything higher then 5.1.4,

(as i manually Updated the "My Installs" from 3.X.X to the current 5.1.4 that you see here)

Link to comment
Share on other sites

This is my fix for the Quantity Price Discount Miscalculation:

Using a programmer's text editor, open for editing the file /classes/catalogue.class.php

In the function getProductData(), find:
$this->getProductPrice($product, $quantity);
Change to:
$this->getProductPrice($product, $quantity, $options_identifier);

Change:
public function getProductPrice(&$product_data, $quantity = 1) {
To:
public function getProductPrice(&$product_data, $quantity = 1, $options_identifier_string = null) {

Find:

if (($pricing = $GLOBALS['db']->select('CubeCart_pricing_quantity', array('quantity', 'price'), $search, array('quantity' => 'ASC', 'price' => 'ASC'))) !== false) {
  foreach ($pricing as $price) {
    $prices[$price['quantity']] = ($GLOBALS['config']->get('config', 'catalogue_sale_mode')==2) ? ($price['price'] - ($price['price'] / 100) * $GLOBALS['config']->get('config', 'catalogue_sale_percentage')) : $price['price'];
  }
  krsort($prices);
  // Ok so we need to get quantity for other items with same product ID for quantity discounts.
  // e.g. 1 x Blue Widget + 2 x Red Widget
  if(is_array($GLOBALS['cart']->basket['contents'])) {
    foreach($GLOBALS['cart']->basket['contents'] as $item) {
      $quantity = ($item['id']==$product_id) ? ($quantity + $item['quantity']) : $quantity;
    }
  }

  foreach ($prices as $quant => $price) {
    if ($quant > $quantity) {
      continue;
    } else {
      //If the sale price is still better than the quantity price use the sale price
      if (!$sale || ((double)$product_data['sale_price'] == 0) || ($sale && $product_data['sale_price'] > $price)) {
        $product_data['price'] = $price;
        $product_data['sale_price'] = $price;
      }
      break;
    }
  }
}

Change to:

if (($pricing = $GLOBALS['db']->select('CubeCart_pricing_quantity', array('quantity', 'price'), $search, array('quantity' => 'ASC', 'price' => 'ASC'))) !== false) {
  foreach ($pricing as $price) {
    $prices[$price['quantity']] = ($GLOBALS['config']->get('config', 'catalogue_sale_mode')==2) ? ($price['price'] - ($price['price'] / 100) * $GLOBALS['config']->get('config', 'catalogue_sale_percentage')) : $price['price'];
  }
  krsort($prices);
  // Ok so we need to get quantity for other items with same product ID for quantity discounts.
  // e.g. 1 x Blue Widget + 2 x Red Widget
  $quantity_others = 0;
  if(is_array($GLOBALS['cart']->basket['contents'])) {
    foreach($GLOBALS['cart']->basket['contents'] as $item) {
      if(isset($item['options_identifier']) && ($item['options_identifier'] != $options_identifier_string)) {
        $quantity_others = ($item['id']==$product_id) ? ($quantity_others + $item['quantity']) : $quantity_others;
      }
     }
   }

  foreach ($prices as $quant => $price) {
    if ($quant > ($quantity + $quantity_others)) {
      continue;
    } else {
      //If the sale price is still better than the quantity price use the sale price
      if (!$sale || ((double)$product_data['sale_price'] == 0) || ($sale && $product_data['sale_price'] > $price)) {
        $product_data['price'] = $price;
        $product_data['sale_price'] = $price;
      }
      break;
    }
  }
}
Link to comment
Share on other sites

The function getProductData begins at line 453 (your image does not show line numbers). For the first edit, you are to find the statement:

$this->getProductPrice($product, $quantity);

which is at line 497 -- 44 lines below the function start.

 

The second edit is at line 603, the start of the function getProductPrice.

 

The third edit spans lines 653-678, still part of the getProductPrice function, but is 50 lines below the function start.

Link to comment
Share on other sites

Doesn't seem to be working, that 3rd one was a pain in the neck to find

 

 

Edit:

So i noticed the line...

 

      if(isset($item['options_identifier']) && ($item['options_identifier'] != $options_identifier_string)) {

 

was missing so i added it and the whole store went down

 

Edit #2:

 

So instead of going through change #3 line by line, (i made a back-up of catalogue.class.php) i just Copy/pasted the code into it and now it seems to be working as intended

Edited by YnZs
Link to comment
Share on other sites

  • 9 months later...

Welcome UncleSam! Glad to see you made it to the forums.

 

Please let us know what version of CubeCart you are using.

 

Is there only one product in the basket? Or might there be more than one variation (size, color) of the same product in the basket?

Link to comment
Share on other sites

Heyy Thanks,

 

It says 5.2.1 in the Dashboard > Store Overview.

 

Its exactly the same issue as YnZs's , I get "undefined" when delete the quantity discount option.

 

My options are set as :

 

Retail price is 13$.

 

Option 1 : Price 12$ > quantity 10.

 

Option 2 : Price 10$ > quantity 12.

 

but when I update it in the basket it takes price as 10$ for all quantities over 4.

 

Thanks !!

Link to comment
Share on other sites

With regard to the 'undefined', in the file /admin/skins/default/templates/products.index.php, (CC527 line 222), find:

<div><span class="actions"><a href="#" rel="{$discount.discount_id}" class="remove" name="discount_delete"><img src="{$SKIN_VARS.admin_folder}/skins/{$SKIN_VARS.skin_folder}/images/delete.png" alt="{$LANG.common.delete}" /></a></span><label><span class="editable number-right" name="discount[{$discount.discount_id}][quantity]" title="Click to edit">{$discount.quantity}</span></label>

We will edit just this part:

<a href="#" rel="{$discount.discount_id}" class="remove" name="discount_delete">

Change it to this:

<a href="#" rel="{$discount.discount_id}" class="remove" name="discount_delete" title="{$LANG.notification.confirm_delete}">

 

I will compare the code in CC527 (works fine) against CC521 and try to determine what needs to be changed so that your CC521 will work correctly. Be back shortly.

Link to comment
Share on other sites

There have been changes between CC521 and CC522, and has been the same code since.

So, using a programmer's text editor, in the file /classes/catalogue.class.php, near line 657, find:

                krsort($prices);
                // Ok so we need to get quantity for other items with same product ID for quantity discounts.
                // e.g. 1 x Blue Widget + 2 x Red Widget
                if(is_array($GLOBALS['cart']->basket['contents'])) {
                    foreach($GLOBALS['cart']->basket['contents'] as $item) {
                        $quantity = ($item['id']==$product_id) ? ($quantity + $item['quantity']) : $quantity;
                    }
                }
                  
                foreach ($prices as $quant => $price) {
                    if ($quant > $quantity) {
                        continue;
                    } else {
                        //If the sale price is still better than the quantity price use the sale price
                        if (!$sale || ((double)$product_data['sale_price'] == 0) || ($sale && $product_data['sale_price'] > $price)) {
                            $product_data['price'] = $price;
                            $product_data['sale_price'] = $price;
                        }
                        break;
                    }
                }
            }

            foreach ($GLOBALS['hooks']->load('class.cubecart.product_price') as $hook) include $hook;

            return $product_data;
        }

        return false;
    }

Replace that with:

                krsort($prices);
                // Ok so we need to get quantity for other items with same product ID for quantity discounts.
                // e.g. 1 x Blue Widget + 2 x Red Widget
                $original_quantity = $quantity;
                if(is_array($GLOBALS['cart']->basket['contents'])) {
                    $quantity = 0;
                    foreach($GLOBALS['cart']->basket['contents'] as $hash => $item) {
                        if($item['id']==$product_id) {
                            $quantity += $item['quantity'];
                        }
                    }    
                }
                $quantity = ($quantity==0) ? $original_quantity : $quantity;
                  
                foreach ($prices as $quant => $price) {
                    if ($quant > $quantity) {
                        continue;
                    } else {
                        //If the sale price is still better than the quantity price use the sale price
                        if (!$sale || ((double)$product_data['sale_price'] == 0) || ($sale && $product_data['sale_price'] > $price)) {
                            $product_data['price'] = $price;
                            $product_data['sale_price'] = $price;
                        }
                        break;
                    }
                }
            }

            foreach ($GLOBALS['hooks']->load('class.cubecart.product_price') as $hook) include $hook;

            if($sale && $product_data['sale_price'] >= $product_data['price']) {
                $product_data['ctrl_sale'] = false;
            }
            return $product_data;
        }

        return false;
    }

Not all the lines have been changed, but it is easier to replace the whole bunch than it is to find each little change.

 

A programmer's text editor is specially purposed to write code. Such an editor is not a word processor. NotePad++ is good and free, and there may be a text editor as a tool in your hosted account's Control Panel. Do not use NotePad that comes with Windows, nor any kind of word processor.

Link to comment
Share on other sites

Thank you so much !!

 

The problem is resolved now, I installed a free version of cube cart (latest one) and copied the catalogue.class file from it to my live installation and it worked.

 

however, there are many other issues as well so I was curious to know can I upgrade my website to the latest version without disturbing the "Theme and other Plugins."

 

or would it affect the theme or any other settings.

 

Thanks again :-)

Link to comment
Share on other sites

The nature of plugins and themes are claimed to be able to survive upgrades. That is, when all of CubeCart's core code is replaced, properly written plugins and custom skins are not overwritten, and will continue to be available and function under the new installation.

 

Practically, however, testing will need to be done to make sure that the plugin code is still compatible with the new CubeCart code. (Case in point, a well-known third-party developer's products seem to have become incompatible over time.)

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
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...