Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

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

 
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:  65
Joined:  2008-04-08
 
zdzisekg - 01 May 2008 09: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:  30
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
 
gfoxjr
Jr. Member
 
Total Posts:  14
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:  11
Joined:  2008-07-11
 

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:  131
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:  11
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
Sr. Member
 
Total Posts:  128
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?

 
Magento Community Magento Community
Magento Community
Magento Community
 
ashish96
Member
 
Avatar
Total Posts:  63
Joined:  2009-01-21
Gujarat, India
 

why to hack magento core..
when u can easily import configurable products with price n all other stuff…
u can check the core part o f magento which handles configurable products…
so no need to do ‘hack’…
just follow the process of magento....

 
Magento Community Magento Community
Magento Community
Magento Community
 
GS Tony
Jr. Member
 
Avatar
Total Posts:  21
Joined:  2009-02-21
Santa Monica
 
ashish96 - 07 April 2009 10:20 PM

why to hack magento core..
when u can easily import configurable products with price n all other stuff…
u can check the core part o f magento which handles configurable products…
so no need to do ‘hack’…
just follow the process of magento....

But where do you check?

 
Magento Community Magento Community
Magento Community
Magento Community
 
oxerbok
Jr. Member
 
Total Posts:  14
Joined:  2010-09-22
 

Hallo,
im have a problem.
I already have a product datas and datas from his variants. but i wont to get only! the diffrent (relevant attributes).

exp.:
Product 1 has a 2 relevant attributes for his Variants: 1. color, 2. size
4 variants of products:

Product 2 - S green
Product 3 - S black
Product 4 - L green
Product 5 - L black

i wont to get only this attributes nothing else:
s-green, s-black,
l-green, l-black.

and its for a shell, not in magento context.

<?php

require_once 'app/Mage.php';
Mage::app('default');
$productId  3;
$product Mage::getModel('catalog/product')->load($productId);

with

$childProducts Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product);

i get everything, but i wont only the relevant attributes.

somebody can help?
thx

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top