Try the Demo

Magento

eCommerce Software for Online Growth

Magento Forum

Our new hosted solution for small & emerging businesses
   
Page 1 of 2
How do I make configurable products share the same tier for pricing? 
 
rioteeru
Jr. Member
 
Total Posts:  13
Joined:  2009-07-23
 

I have sneakers I wish to sell on my website. If they buy 1 pair it’s 1 price, 6 or more pairs is another price, and a dozen or more is yet another price.

However, when I make configurable products, i’ve found that they have to buy 12 pieces of 1 size and 1 color to get the price. If they buy 1 of each size, it charges full price.

Anyone know of a fix or workaround to get this functioning as stated?

Any help would be greatly appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rioteeru
Jr. Member
 
Total Posts:  13
Joined:  2009-07-23
 

I found http://www.tridian.com/developer-blog/tier-pricing-in-magento/ which supposedly works for some people. I made the post (Fernando) but can’t get the sytem to work. Anyone mind taking a look at it and seeing if they can get it running and letting me know how. It would be greatly appreciated.

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
rioteeru
Jr. Member
 
Total Posts:  13
Joined:  2009-07-23
 

Anyone have any idea? I’ve been bashing my head around trying to figure it out but so far nothing.

ANY help would be greatly appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jward1983
Jr. Member
 
Total Posts:  17
Joined:  2009-06-15
 

I don’t understand.

How is it not working for you? What exactly is happening? How exactly are you trying to implement it?

Do you have more than 1 configurable product defined in your products section that you’re trying to combine for tiered pricing? if so, then this solution will not work. I ran into that particular roadblock and used the same method from the link you posted above, but wrote the php code differently to encapsulate more than 1 configurable product.

the solution posted in the thread linked above only works for a single configurable product with options defined for it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rioteeru
Jr. Member
 
Total Posts:  13
Joined:  2009-07-23
 

Weird, the code seems like it’d work for any configurable product. Maybe not, I just started with magento recently so I don’t understand how all of the code works yet.

Mind helping me out with a piece of code that would work for all configurable products?

 
Magento Community Magento Community
Magento Community
Magento Community
 
jward1983
Jr. Member
 
Total Posts:  17
Joined:  2009-06-15
 

The reason that it doesn’t encompass all configurable products that you create in your products admin section is because this particular fix looks at the SKU of each item in your cart to determine how to do the tiered pricing.

When the cart calculates the price to display when you view your shopping cart, it takes a product and passes it through the php code (easily traced as it generally shows up as $product), and in the case of tiered pricing, the default Magento logic behaves as follows:

1) Check product quantity at this slot in the shopping cart.
2) If that quantity matches a tier, it gets applied.

The “fix” code that is referenced in the thread above enhances that process as follows:
1) Get product SKU (this is the SKU of the configurable product. **Note that Magento’s cart stores both the configurable product SKU and whatever simple product(s) are tied to that from the selections made from the configurable options as items are added by users of the store
2) Loop all items in the cart, get their quantity and store an array of quantities and SKU’s
3) Sum up all quantities in the cart where the configurable product’s SKU matches up - this gives the desired quantity to pass to the tiered pricing scheme because it says “ok I have Configurable product X which was added to the cart both in color red and color blue, giving me 2 unique records in my shopping cart, but the configurable product is the same at the end of the day, just differing simple products. Find me everything with the SKU for product X”. And then it uses that quantity to calculate the tiered price that is tied to the SKU of the configurable product.

That’s why if you have let’s say, Configurable Product X and Configurable Product Y and you want tiered pricing to manifest itself across both of those products it won’t work. The fix above would calculate all quantities for product X and do tiered pricing for it, then it would do the same for product Y. Independent summations of quantities due to the difference in SKU’s.

Now, my current client has a single product that they sell. It comes in several colors and sizes. The problem is they want to make it look like their site has more products than it really does, so they didn’t want a single configurable product with dropdown selections for Size and Color.

Instead, they wanted this one single product to be listed once for each available color, and then just have the Size option be configurable.

So if you were to navigate to the category for that product it would show 6 listings as separate configurable products:
Product - Red
Product - Black
Product - Blue
etc etc

Then if you clicked to view the detail of any of those configurable products, you could select the desired size from a dropdown.

This caused an immediate problem for me as a requirement because although the solution from the thread you linked above would solve the issues of when people purchase a product in more than 1 size i.e. configurable option, it would not cover this case where we technically have the same product spanned across configurable products.

They wanted tiered pricing to span all of these because at the end of the day, it’s all just the same product.

So for me I was able to tweak the php code to just look at all configurable products and ignore the SKU. Instead I could just look at the product type attribute in code and say “if this is configurable, add the quantity to my total” and then when I was done I’d just pass that quantity to the tiered pricing calculation.

However, my case is a simple one. If you want to have groupings of configurable products that can be tiered together, the change to my code is actually quite simple. All it would require is that you have a naming scheme for your configurable products to logically group them together. I would probably add a custom attribute to the attribute set of my configurable products (this would not be visible on the front-end).

Then in code as you’re getting a tiered price, you basically take the product’s attribute and look for any other configurable products that are in your current shopping cart that have the same attribute value.

Below is the code I tweaked for my purposes, but remember that this is dumbed down to encompass anything that’s configurable that’s in the shopping cart, because my client only has 1 product and will for quite some time, so for me, creating groupings based on custom attributes as I noted above is rather useless.

Not enough room in this post still for it so see my next post.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jward1983
Jr. Member
 
Total Posts:  17
Joined:  2009-06-15
 

<?php class Foreverlazy_Catalog_Model_Product_Type_Configurable_Price extends Mage_Catalog_Model_Product_Type_Configurable_Price
{
    
/**
     * Get product final price
     *
     * @param   double $qty
     * @param   Mage_Catalog_Model_Product $product
     * @return  double
     */
    
public function getFinalPrice($qty=null$product)
    
{
        
if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
            
return $product->getCalculatedFinalPrice();
        
}

        $finalPrice 
parent::getFinalPrice($qty$product);

        
// Call config product tier pricing function - Chris Lohman 1/6/2009
        /* This allows for tier price to affect configurable items of different sizes, colors, etc.
         * so that when you have some qty of each, the total will be counted towards the tier pricing matrix.
         */
        
$shoppingCartItemCount count(Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection());
        if(
$shoppingCartItemCount 0)
        
{
             $tierPrice 
$this->calcConfigProductTierPricing($product);
             if(
$tierPrice 0)
             
{
                 $finalPrice 
$tierPrice;
             
}
        }
        $product
->getTypeInstance(true)
            ->
setStoreFilter($product->getStore(), $product);
        
$attributes $product->getTypeInstance(true)
            ->
getConfigurableAttributes($product);

        
$selectedAttributes = array();
        if (
$product->getCustomOption('attributes')) {
            $selectedAttributes 
unserialize($product->getCustomOption('attributes')->getValue());
        
}
        $basePrice 
$finalPrice;
        foreach (
$attributes as $attribute{
            $attributeId 
$attribute->getProductAttribute()->getId();
            
$value $this->_getValueByIndex(
                
$attribute->getPrices() ? $attribute->getPrices() : array(),
                isset(
$selectedAttributes[$attributeId]) ? $selectedAttributes[$attributeId] null
            
);

            if(
$value{
                
if($value['pricing_value'!= 0{
                    $finalPrice 
+= $this->_calcSelectionPrice($value$basePrice);
                
}
            }
        }
        $product
->setFinalPrice($finalPrice);
        return 
max(0$product->getData('final_price'));
    
}


    
/**
     * Get product final price via configurable product's tier pricing structure.  Uses qty of parent item to determine price.
     *
     * @param   float $price
     * @param   Mage_Catalog_Model_Product $product
     * @return  float
     */
    
public function calcConfigProductTierPricing($product)
    
{
        $totalQty 
0;
        
$tierPrice 0;
        if(
$items Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection())
        
{
            
foreach ($items as $item)
            
{
                 $prodType 
$item->getData('product_type');
                 if (
$prodType == 'configurable')
                 
{
                      $totalQty 
+= $item->getQty();
                 
}
            }

            $tierPrice 
$this->getTierPrice($totalQty$product);
        
}
        
return $tierPrice;
    
}

?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
rioteeru
Jr. Member
 
Total Posts:  13
Joined:  2009-07-23
 

Thanks for the post! It’s very helpful (I haven’t coded much in the past few years so i’m a bit rusty).

However, I tried changing the code a bit in my function to such

/**
 * Get product final price via configurable product's tier pricing structure.  Uses qty of parent item to determine price.
 *
 * @param   float $price
 * @param   Mage_Catalog_Model_Product $product
 * @return  float
 */
public function calcConfigProductTierPricing($product)
{
    $totalQty 
0;
        
$tierPrice 0;
        if(
$items Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection())
        
{
            
foreach ($items as $item)
            
{
                $catid 
$item->getProduct()->getCategoryId();
                if(
$catid == '48')
                
{
                    $totalQty 
+= $item->getQty();
                
}
            }
            $tierPrice 
$this->getTierPrice($totalQty$product);
        
}
        
return $tierPrice;
}

Now, when I try adding the product to my cart, I receive the following error.

Fatal error: Unsupported operand types in /homepages/39/d290726294/htdocs/cuba/app/code/core/Mage/Directory/Model/Currency.php on line 168

I try commenting out lines to see where the problem might be, and then the function throws the exception USD - USD Undefined.

Anyone know what might cause such errors? I can still add regular products, but I can’t add any configurable products to my cart.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rioteeru
Jr. Member
 
Total Posts:  13
Joined:  2009-07-23
 

I’ve come across yet another error now D:

When I try to load a configurable product in product view it comes up totally blank. Nothing shows in the product view at all. Is there some sort of debugging or something I can turn on to see where the problems are occuring?

 
Magento Community Magento Community
Magento Community
Magento Community
 
jward1983
Jr. Member
 
Total Posts:  17
Joined:  2009-06-15
 

When your page loads with no product details on it, check the page source in your browser. I ran into several errors like that while I was writing the logic that I used when I had a few bugs to work out. For me, the function was returning a value of “array” as my tiered price which was being passed in to other price calculation methods in the base that caused my product details to not show up. Particularly for me it was in the tax calculation process. Granted I had no tax associated but the logic still executes, it’s just that the nominal scenario (no tax) returns 0 so nothing gets appended to the price total.

I’m a C# developer by trade, so I’m used to having a pretty rich GUI debugging environment, so I may not know the best way to debug PHP code, but for me I just go old school and add a bunch of echo commands to write out the variables and their values, or echo a note for when I’m inside a certain IF/ELSE conditional.

That’s how I worked my way through the bugs in my code, anyway.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jward1983
Jr. Member
 
Total Posts:  17
Joined:  2009-06-15
 

regarding your first error message about unsupported operand, I would throw in some ECHO statements when you pull the category ID and see what values are actually coming back.

I can’t remember if getCategoryId() returns a string or a number, but either way you’re currently checking the IF block for a string value of ‘48’, so if the $catid variable you are assigning is a numeric, then I wouldn’t be surprised if you got that unsupported operand error. I’d verify your datatypes.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jward1983
Jr. Member
 
Total Posts:  17
Joined:  2009-06-15
 

Oh and also be sure that $item->getProduct() is a valid function call. The $item variable in $items is already a product from the shopping cart itself, so you may just be looking to use $item->getCategoryId()

Not entirely sure on that as I don’t know every in and out of the magento API yet, but definitely something to verify and rule out as a possible root of your problems.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rioteeru
Jr. Member
 
Total Posts:  13
Joined:  2009-07-23
 

Ok, i’ve pinpointed my problem. It’s the same tax issue you had with arrays i’d imagine.

var optionsPrice = new Product.OptionsPrice(Array<br />
<
b>Fatal error</b>:  Unsupported operand types in <b>/homepages/39/d290726294/htdocs/cuba/app/code/core/Mage/Tax/Helper/Data.php</bon line <b>374</b><br />

Only thing is how would I get just the price from the array? Is it like c++ or anything where it’s just array_name[1]?

 
Magento Community Magento Community
Magento Community
Magento Community
 
rioteeru
Jr. Member
 
Total Posts:  13
Joined:  2009-07-23
 

I just need to fix this last bit and the code is working fine. The error i’m currently getting which I posted above only occurs when I have no other items in cart. However, if I add ANY item to the cart, the tax issue is no longer occuring. Is this because of a call to get a quote?

$items = Mage::getSingleton(’checkout/session’)->getQuote()->getItemsCollection()

Would there be any way to check the checkout if there are any current products before running that command?

 
Magento Community Magento Community
Magento Community
Magento Community
 
rioteeru
Jr. Member
 
Total Posts:  13
Joined:  2009-07-23
 

I’ve changed the code every so slightly. Thanks for the input jward, it’s been really helpful.

I’ve been able to fix the problem with the page showing up blank if the cart is empty by adding ->getItems() after getItemCollection().

Now however, when I try adding to the cart, I get the following error…

Fatal errorUnsupported operand types in /homepages/39/d290726294/htdocs/cuba/app/code/core/Mage/Directory/Model/Currency.php on line 168

This is my code currently.

public function calcConfigProductTierPricing($product)
    
{
        $totalQty 
0;
        
$tierPrice 0;
        if(
$items Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection()->getItems())
        
{
            
foreach ($items as $item)
            
{
                $catid 
$item->getProduct()->getCategoryId();
                if(
$catid == 48)
                
{
                    $totalQty 
+= $item->getQty();
                
}
            }
            $tierPrice 
$this->getTierPrice($totalQty$product);
        
}
        
return $tierPrice;
    
}

I’ve never had this much trouble writing a few lines of code… lol

 
Magento Community Magento Community
Magento Community
Magento Community
 
jward1983
Jr. Member
 
Total Posts:  17
Joined:  2009-06-15
 

Just out of curiosity, you did also modify the getFinalPrice function in your extended Price.php file, right? With the following code:

$shoppingCartItemCount count(Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection());
        if(
$shoppingCartItemCount 0)
        
{
             $tierPrice 
$this->calcConfigProductTierPricing($product);
             if(
$tierPrice 0)
             
{
                 $finalPrice 
$tierPrice;
             
}
        }

This ensures that the tax issues and others will not come up because tiered price never gets calculated here unless there is at least 1 item in the cart.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 2
 
© Copyright Magento Inc.
Privacy Policy|Terms of Service
Magento Community Count
819302 users|765 users currently online|519717 forum posts