Call-back icon  Sales: Call 877.832.5289 (N America)|310.295.4144 (International)

Magento

eCommerce Software for Online Growth

Magento Forum

   
hacking configurable product price. need advice. 
 
zdzisekg
Jr. Member
 
Total Posts:  16
Joined:  2008-03-20
 

this is related to this post http://www.magentocommerce.com/boards/viewthread/7326/

I need to hack the “configurable product” so that the price reflects the price of the underlying “simple product.

I have ex. a configurable product with the following attributes:
size
paper type
fold

one of the simple products looks like this:
Size = 11 x 8 1/2”
Paper Type = 60#
Fold = None
The price for the simple product is $1,335

What I want to happen is if a costumers configures the “configurable product” with size=11 x 8 1/2”, Paper Type = 60# and Fold = None, the price of the configurable product should show $1,335

What’s the best / easiest way of doing this?

P.S.
The way “configurable product” pricing functions does not accomplish what I need.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1771
Joined:  2007-08-07
Los Angeles
 

In this case the most unclear part would be the calculation of price deltas in option dropdowns.

Currently it is simple, because the options themselves have explicit price change.

When you have dynamically calculated price deltas, they will need to be changed for all options each time you change any of them. And the numbers might not be logical to the customer.

If you remove the price deltas from dropdowns, then it becomes much simpler, you will need to keep the final prices for each SKU and update the price on frontend with javascript.

The javascript will need to generate the same add to cart url as it would be a simple product.

That should be it.

 Signature 

- I would love to change the world, but they won’t give me the source code -

 
Magento Community Magento Community
Magento Community
Magento Community
 
zdzisekg
Jr. Member
 
Total Posts:  16
Joined:  2008-03-20
 

I don’t need any pricing information coming from the “configurable product” it self. All I really need is once the options are set, pull the price of the corresponding “simple product”.

Anyway to do this in core magento? All I know is some php. Javascript is black magic to me.

Thanx

 
Magento Community Magento Community
Magento Community
Magento Community
 
dev722z
Member
 
Total Posts:  50
Joined:  2008-04-09
 
zdzisekg - 01 May 2008 10:35 AM

I don’t need any pricing information coming from the “configurable product” it self. All I really need is once the options are set, pull the price of the corresponding “simple product”.

+1

dev722z

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vofka
Jr. Member
 
Avatar
Total Posts:  26
Joined:  2008-06-19
 

2 zdzisekg:
Go to mage/catalog/block/product/view/type/configurable.php

add this code in it

public function getAttributesInfo()
    
{
        $attributes 
= array();
        
$options = array();
        
$store Mage::app()->getStore();
        foreach (
$this->getAllowProducts() as $product{
            $productId  
$product->getId();

            foreach (
$this->getAllowAttributes() as $attribute{
                $productAttribute 
$attribute->getProductAttribute();
                
$attributeValue $product->getData($productAttribute->getAttributeCode());
                if (!isset(
$options[$productAttribute->getId()])) {
                    $options[$productAttribute
->getId()= array();
                
}

                
if (!isset($options[$productAttribute->getId()][$attributeValue])) {
                    $options[$productAttribute
->getId()][$attributeValue] = array();
                
}
                $options[$productAttribute
->getId()][$attributeValue][] $productId;
            
}
        }

        $this
->_resPrices = array(
            
$this->_preparePrice($this->getProduct()->getFinalPrice())
        );

        foreach (
$this->getAllowAttributes() as $attribute{
            $productAttribute 
$attribute->getProductAttribute();
            
$attributeId $productAttribute->getId();
            
$info = array(
               
'id'        => $productAttribute->getId(),
               
'code'      => $productAttribute->getAttributeCode(),
               
'label'     => $attribute->getLabel(),
               
'options'   => array()
            );

            
$optionPrices = array();
            
$prices $attribute->getPrices();
            if (
is_array($prices)) {
                
foreach ($prices as $value{
                    
if(!$this->_validateAttributeValue($attributeId$value$options)) {
                        
continue;
                    
}

                    $info[
'options'][] = array(
                        
'id'    => $value['value_index'],
                        
'label' => $value['label'],
                        
'price' => $this->_preparePrice($value['pricing_value']$value['is_percent']),
                        
'products'   => isset($options[$attributeId][$value['value_index']]) ? $options[$attributeId][$value['value_index']] : array(),
                    );
                    
$optionPrices[] $this->_preparePrice($value['pricing_value']$value['is_percent']);
                    
$this->_registerAdditionalJsPrice($value['pricing_value']$value['is_percent']);
                
}
            }
            
/**
             * Prepare formated values for options choose
             */
            
foreach ($optionPrices as $optionPrice{
                
foreach ($optionPrices as $additional{
                    $this
->_preparePrice(abs($additional-$optionPrice));
                
}
            }
            
if($this->_validateAttributeInfo($info)) {
               $attributes[$attributeId] 
$info;
            
}
        }
        
/*echo '<pre>';
        print_r($this->_prices);
        echo '</pre>';die();*/
        
$config = array(
            
'attributes'=> $attributes,
            
'template'  => str_replace('%s''#{price}'$store->getCurrentCurrency()->getOutputFormat()),
            
'prices'    => $this->_prices,
            
'basePrice' => $this->_registerJsPrice($this->_convertPrice($this->getProduct()->getFinalPrice())),
            
'oldPrice'  => $this->_registerJsPrice($this->_convertPrice($this->getProduct()->getPrice())),
            
'productId' => $this->getProduct()->getId(),
            
'chooseText'=> Mage::helper('catalog')->__('Choose option...'),
        );

        return 
$config;
    
}

It’s getJsonConfig() but without Zend_Json…
Call in your configurable.phtml file function getAttributesInfo() and print_r() it like this

print_r($this->getAttributesInfo())
if you understand php you’ll understand what to do with it.

Enjoy…

 
Magento Community Magento Community
Magento Community
Magento Community
 
zdzisekg
Jr. Member
 
Total Posts:  16
Joined:  2008-03-20
 

thanx, I’ll give it a try

 
Magento Community Magento Community
Magento Community
Magento Community
 
foxpromedia
Jr. Member
 
Total Posts:  9
Joined:  2008-06-09
 

Did this work for you?

 
Magento Community Magento Community
Magento Community
Magento Community
 
zdzisekg
Jr. Member
 
Total Posts:  16
Joined:  2008-03-20
 

in he end I decided to go with PrestaShop instead of magento so I never tried it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Chris Wiech
Jr. Member
 
Total Posts:  5
Joined:  2008-07-12
 

I tried the solution suggested above, but without success. What I have done:
- added the new method to: app/code/core/Mage/Catalog/Block/Product/View/Type/Configurable.php
- changed the template file: app/design/frontend/pool/default/template/catalog/product/view/type/options/configurable.phtml

In configurable.phtml I’m unsure where or in which context I have to add print_r($this->getAttributesInfo()) ?

First try in configurable.phtml:
Change line 38 to:

var spConfig = new Product.Config(<?php print_r($this->getAttributesInfo())  ?>);
Results in error:
Invalid method Mage_Catalog_Block_Product_View_Type_Configurable::_registerAdditionalJsPrice(Array
(
    
[0] => 
    
[1] => 0
)
)

Can someone please tell where and how I have to add this new line?

Thanks.
Chris

 
Magento Community Magento Community
Magento Community
Magento Community
 
nate001
Jr. Member
 
Total Posts:  14
Joined:  2008-08-15
 

I am also interested in how to get this working properly.  Currently I am trying to find a way to use the price rules ( 10% site wide ) while having hte discount apply to the options in a configurable product as well.  This seem like unjustified overhead for what Im looking to do, Im running out of options as I have been unsuccessful finding an alternative.

If we can get a solution that works properly Ill be happy to go to all the other threads Ive book marked and offer this solution

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
zep007
Sr. Member
 
Avatar
Total Posts:  82
Joined:  2008-05-15
Connecticut
 

OK,

So it seems that if I uncomment _registerAdditionalJsPrice (protected function) I don’t get the error you guys are posting. 

I put getAttributesInfo into here

var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);

So here is the good news and the bad news.  By un-commenting that function (which Im sure was commented out for a reason) there is not thrown exception, but a softfail, the dropdown boxes do not have any options in them.

if you throw this in there:

<? echo 'getJsonConfig = '.'<br>';  
print_r($this->getJsonConfig());  ?><br><br

<? echo 'getAttributesInfo = '.'<br>';  
 
print_r ($this->getAttributesInfo());?>

you can see that the calculations are not being done, the same information as the JsonConfig is put into an array, but into an array that is not parsed the same way as JsonConfig because of

return Zend_Json::encode($config)
which formats the data so it can be read in

Can anyone help me understand why keeping the data in unformatted array is closer to the desired objective then leaving it parsed correctly?

Im going to hack at it, but if someone has got this working please post!

 
Magento Community Magento Community
Magento Community
Magento Community
 
rjfrasca
Jr. Member
 
Total Posts:  7
Joined:  2008-08-10
 

Did anyone ever get this hack to work.  I have tried several times, and have been unsuccessful.

The entire configurable model used by Magento has quadroupled my development time for clients with configurable products.

 
Magento Community Magento Community
Magento Community
Magento Community
 
bmartus
Member
 
Total Posts:  68
Joined:  2008-05-22
Greenville, TX
 

I had thought once they fixed the inventory issue and simple product SKU not showing on the invoice, order info, etc., that they would’ve pulled the price and other product info at the same time.

Anybody submit this as a bug or feature request yet?

 Signature 

Brandon Martus

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
 
Sales: Call 877.832.5289 (North America) 310.295.4144 (International)
© Copyright 2008 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
53192 users|714 users currently online|107221 forum posts