public function getJsonConfig()
 {
     // let's reset some variables first
     $this->setAllowProducts(null);
     // and now call geJsonConfig
     return parent::getJsonConfig();
 }
 public function getJsonConfig()
 {
     $config = Mage::helper('core')->jsonDecode(parent::getJsonConfig());
     $config['template'] = str_replace('%s', '#{price}', $this->getCurrencyOutputFormat());
     $config['productStock'] = array();
     foreach ($this->getAllowProducts() as $simple) {
         $config['productStock'][$simple->getId()] = $simple->isSaleable() ? $simple->getStockItem()->getQty() : 0;
     }
     $i = 1;
     foreach ($this->getAllowAttributes() as $cfgAttr) {
         $_aId = $cfgAttr->getAttributeId();
         if (!isset($config['attributes'][$_aId])) {
             continue;
         }
         $config['attributes'][$_aId]['idx'] = $i++;
         $config['attributes'][$_aId]['identifyImage'] = $cfgAttr->getData('identify_image');
         $_sk = sprintf('super_attribute/%s/%s', $this->getProduct()->getId(), $cfgAttr->getAttributeId());
         $_pAttr = $cfgAttr->getProductAttribute();
         $config['perAttrChooseText'][$_aId] = Mage::helper('udprod')->__('- Select %s -', $_pAttr->getFrontend()->getLabel());
         $_swatchMap = $_pAttr->getSwatchMap();
         if (!is_array($_swatchMap)) {
             $_swatchMap = (array) Mage::helper('core')->jsonDecode($_swatchMap);
         }
         if (!empty($config['attributes'][$_aId]['options'])) {
             foreach ($config['attributes'][$_aId]['options'] as &$opt) {
                 if (isset($_swatchMap[$opt['id']])) {
                     $opt['swatch'] = sprintf('%s/catalog/swatch/%s/%s', Mage::getBaseUrl('media'), $_aId, $_swatchMap[$opt['id']]);
                 } else {
                     $opt['swatch'] = Mage::getDesign()->getSkinUrl('images/fpo/ph_swatch.gif');
                 }
             }
             unset($opt);
             if ($config['attributes'][$_aId]['idx'] == 1) {
                 $newOptions = array();
                 $usedValues = array();
                 $simpleProducts = $this->getProduct()->getTypeInstance(true)->getUsedProducts(null, $this->getProduct());
                 foreach ($simpleProducts as $simpleProd) {
                     $usedValues[] = $simpleProd->getData($_pAttr->getAttributeCode());
                 }
                 $usedValues = array_unique($usedValues);
                 $defColor = $this->getDefaultColorByImage();
                 foreach ($config['attributes'][$_aId]['options'] as $opt) {
                     foreach ($usedValues as $usedValue) {
                         if ($opt['id'] == $usedValue) {
                             if ($defColor == $opt['id']) {
                                 array_unshift($newOptions, $opt);
                             } else {
                                 $newOptions[] = $opt;
                             }
                         }
                     }
                 }
                 $config['attributes'][$_aId]['options'] = $newOptions;
             }
         }
         if ($this->_getSession()->getData($_sk)) {
             $config['attributes'][$_aId]['defaultValueId'] = $this->_getSession()->getData($_sk);
             $config['attributes'][$_aId]['isColor'] = $_pAttr->getAttributeCode() == 'color';
         }
     }
     $this->_getSession()->unsetData('super_attribute');
     return Mage::helper('core')->jsonEncode($config);
 }