public function saveProductOptions($newOptions, array $prevOptions, array $productIds, Varien_Object $group, $prevGroupIsActive = 1, $place = 'apo', $prevStoreOptionsData = array())
 {
     if (isset($productIds) && is_array($productIds) && count($productIds) > 0) {
         $relation = Mage::getResourceSingleton('customoptions/relation');
         $templateId = $group->getId();
         $groupIsActive = $group->getIsActive();
         $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
         $tablePrefix = (string) Mage::getConfig()->getTablePrefix();
         $condition = '';
         if ($place == 'product') {
             $condition = ' AND product_id IN (' . implode(',', $productIds) . ')';
         }
         // get and prepare $optionRelations
         $select = $connection->select()->from($tablePrefix . 'custom_options_relation')->where('group_id = ' . $templateId . $condition);
         $optionRelations = $connection->fetchAll($select);
         if (is_array($optionRelations) && count($optionRelations) > 0) {
             $tmp = array();
             foreach ($optionRelations as $option) {
                 $tmp[$option['product_id']][$option['option_id']] = $option;
             }
             $optionRelations = $tmp;
         } else {
             $optionRelations = array();
         }
         if (isset($newOptions) && is_array($newOptions)) {
             $newOptions = $this->_prepareOptions($newOptions, $templateId, $groupIsActive);
             $prevOptions = $this->_prepareOptions($prevOptions, $templateId, $prevGroupIsActive);
             // comparison arrays
             $diffOptions = $this->comparisonArrays($newOptions, $prevOptions);
             // get all store options
             $select = $connection->select()->from($tablePrefix . 'custom_options_group_store')->where('group_id = ' . $templateId);
             $allStoreOptions = $connection->fetchAll($select);
             foreach ($allStoreOptions as $key => $storeOptions) {
                 if ($storeOptions['hash_options']) {
                     $hashOptions = unserialize($storeOptions['hash_options']);
                 } else {
                     $hashOptions = array();
                 }
                 if (isset($prevStoreOptionsData['store_id']) && $storeOptions['store_id'] == $prevStoreOptionsData['store_id']) {
                     if ($prevStoreOptionsData['hash_options']) {
                         $prevHashOptions = unserialize($prevStoreOptionsData['hash_options']);
                     } else {
                         $prevHashOptions = array();
                     }
                     // link to reset no deault!!
                     foreach ($prevHashOptions as $optionId => $option) {
                         // add to check remove store option
                         if (!isset($hashOptions[$optionId])) {
                             $hashOptions[$optionId] = array('option_id' => $option['option_id'], 'type' => $option['type']);
                         }
                         if (isset($option['values'])) {
                             foreach ($option['values'] as $valueId => $value) {
                                 // add to check remove store option value
                                 if (!isset($hashOptions[$optionId]['values'][$valueId])) {
                                     $hashOptions[$optionId]['values'][$valueId]['option_type_id'] = $value['option_type_id'];
                                 } else {
                                     // add prev specials data
                                     if (isset($value['specials'])) {
                                         $hashOptions[$optionId]['values'][$valueId]['prev_specials'] = $value['specials'];
                                     }
                                     // add prev tiers data
                                     if (isset($value['tiers'])) {
                                         $hashOptions[$optionId]['values'][$valueId]['prev_tiers'] = $value['tiers'];
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $allStoreOptions[$key]['hash_options'] = $hashOptions;
             }
             //                print_r($newOptions);
             //                print_r($prevOptions);
             //                print_r($diffOptions);
             //                exit;
             foreach ($productIds as $productId) {
                 $realOptionIds = array();
                 $options = $newOptions;
                 // work copy options
                 // $optionRelations
                 // update options
                 if (isset($optionRelations[$productId])) {
                     foreach ($optionRelations[$productId] as $optionId => $prevOption) {
                         //$optionId = $prevOption['option_id'];
                         $prevOption = Mage::getModel('catalog/product_option')->load($optionId);
                         if (isset($options['IGI' . $prevOption->getInGroupId()]) && (!isset($options['IGI' . $prevOption->getInGroupId()]['is_delete']) || $options['IGI' . $prevOption->getInGroupId()]['is_delete'] != 1)) {
                             $option = $options['IGI' . $prevOption->getInGroupId()];
                             if (isset($diffOptions['IGI' . $prevOption->getInGroupId()])) {
                                 $diffOption = $diffOptions['IGI' . $prevOption->getInGroupId()];
                             } else {
                                 $diffOption = array();
                             }
                             $this->saveOption($productId, $diffOption, $optionId, 0, $option['type']);
                             $realOptionIds[$option['option_id']]['value'] = $optionId;
                             if ($this->getGroupByType($option['type']) == self::OPTION_GROUP_SELECT) {
                                 $select = $connection->select()->from($tablePrefix . 'catalog_product_option_type_value')->where('option_id = ' . $optionId);
                                 $prevValues = $connection->fetchAll($select);
                                 if (is_array($prevValues) && count($prevValues) > 0) {
                                     foreach ($prevValues as $prValue) {
                                         if (isset($option['values']['IGI' . $prValue['in_group_id']]) && (!isset($option['values']['IGI' . $prValue['in_group_id']]['is_delete']) || $option['values']['IGI' . $prValue['in_group_id']]['is_delete'] != 1)) {
                                             // update option value
                                             if (isset($prevOptions['IGI' . $prevOption->getInGroupId()]['values']['IGI' . $prValue['in_group_id']])) {
                                                 $prevValue = $prevOptions['IGI' . $prevOption->getInGroupId()]['values']['IGI' . $prValue['in_group_id']];
                                             } else {
                                                 $prevValue = array();
                                             }
                                             if (isset($newOptions['IGI' . $prevOption->getInGroupId()]['values']['IGI' . $prValue['in_group_id']])) {
                                                 $newValue = $newOptions['IGI' . $prevOption->getInGroupId()]['values']['IGI' . $prValue['in_group_id']];
                                             } else {
                                                 $newValue = array();
                                             }
                                             if (isset($diffOption['values']['IGI' . $prValue['in_group_id']])) {
                                                 $diffValue = $diffOption['values']['IGI' . $prValue['in_group_id']];
                                             } else {
                                                 $diffValue = array();
                                             }
                                             if (isset($diffValue['customoptions_qty']) && !$group->getUpdateInventory()) {
                                                 unset($diffValue['customoptions_qty']);
                                             }
                                             $this->saveOptionValue($optionId, $diffValue, $prevValue, $newValue, $prValue['option_type_id'], 0);
                                             $realOptionIds[$option['option_id']][$option['values']['IGI' . $prValue['in_group_id']]['option_type_id']] = $prValue['option_type_id'];
                                             unset($option['values']['IGI' . $prValue['in_group_id']]);
                                         } else {
                                             // delete option value
                                             $connection->delete($tablePrefix . 'catalog_product_option_type_value', 'option_type_id = ' . $prValue['option_type_id']);
                                         }
                                     }
                                 }
                                 // insert option values
                                 if (count($option['values']) > 0) {
                                     foreach ($option['values'] as $value) {
                                         if (isset($value['is_delete']) && $value['is_delete'] == 1) {
                                             continue;
                                         }
                                         if ($group->getOnlyUpdate() && !isset($diffOptions['IGI' . $option['in_group_id']]['values']['IGI' . $value['in_group_id']]['in_group_id'])) {
                                             continue;
                                         }
                                         $this->saveOptionValue($optionId, $value, array(), $value, false, 0);
                                     }
                                 }
                             }
                             unset($options['IGI' . $prevOption->getInGroupId()]);
                         } else {
                             if (isset($prevOption['option_id'])) {
                                 // delete option
                                 $connection->delete($tablePrefix . 'catalog_product_option', 'option_id = ' . $prevOption['option_id']);
                                 $connection->delete($tablePrefix . 'catalog_product_option_type_value', 'option_id = ' . $prevOption['option_id']);
                                 $connection->delete($tablePrefix . 'custom_options_option_view_mode', 'option_id = ' . $prevOption['option_id']);
                                 $connection->delete($tablePrefix . 'custom_options_option_description', 'option_id = ' . $prevOption['option_id']);
                                 $connection->delete($tablePrefix . 'custom_options_option_default', 'option_id = ' . $prevOption['option_id']);
                                 $connection->delete($tablePrefix . 'custom_options_relation', 'group_id = ' . $templateId . ' AND product_id = ' . $productId . ' AND option_id = ' . $prevOption['option_id']);
                             }
                         }
                     }
                 }
                 // insert default options
                 foreach ($options as $option) {
                     if (isset($option['is_delete']) && $option['is_delete'] == 1) {
                         continue;
                     }
                     if ($group->getOnlyUpdate() && isset($optionRelations[$productId]) && !isset($diffOptions['IGI' . $option['in_group_id']])) {
                         continue;
                     }
                     $optionId = $this->saveOption($productId, $option, false, 0, $option['type']);
                     $realOptionIds[$option['option_id']]['value'] = $optionId;
                     $optionRelation = array('option_id' => $optionId, 'group_id' => $templateId, 'product_id' => $productId);
                     $connection->insert($tablePrefix . 'custom_options_relation', $optionRelation);
                     // insert option values
                     if ($this->getGroupByType($option['type']) == self::OPTION_GROUP_SELECT && count($option['values']) > 0) {
                         foreach ($option['values'] as $value) {
                             if (isset($value['is_delete']) && $value['is_delete'] == 1) {
                                 continue;
                             }
                             if ($group->getOnlyUpdate() && isset($optionRelations[$productId]) && !isset($diffOptions['IGI' . $option['in_group_id']]['values']['IGI' . $value['in_group_id']]['in_group_id'])) {
                                 continue;
                             }
                             $optionTypeId = $this->saveOptionValue($optionId, $value, array(), $value, false, 0);
                             $realOptionIds[$option['option_id']][$value['option_type_id']] = $optionTypeId;
                         }
                     }
                 }
                 // insert all store options
                 //print_r($allStoreOptions); exit;
                 foreach ($allStoreOptions as $storeOptions) {
                     foreach ($storeOptions['hash_options'] as $option) {
                         if (isset($realOptionIds[$option['option_id']]['value']) && $realOptionIds[$option['option_id']]['value']) {
                             $optionId = $this->saveOption($productId, $option, $realOptionIds[$option['option_id']]['value'], $storeOptions['store_id'], $option['type']);
                         } else {
                             $optionId = false;
                         }
                         // insert option values
                         if ($optionId && $this->getGroupByType($option['type']) == self::OPTION_GROUP_SELECT && count($option['values']) > 0) {
                             foreach ($option['values'] as $value) {
                                 if (isset($realOptionIds[$option['option_id']][$value['option_type_id']]) && $realOptionIds[$option['option_id']][$value['option_type_id']]) {
                                     $prevValue = $value;
                                     if (isset($value['prev_tiers'])) {
                                         $prevValue['tiers'] = $value['prev_tiers'];
                                     }
                                     if (isset($value['prev_specials'])) {
                                         $prevValue['specials'] = $value['prev_specials'];
                                     }
                                     $this->saveOptionValue($optionId, $value, $prevValue, $value, $realOptionIds[$option['option_id']][$value['option_type_id']], $storeOptions['store_id']);
                                 }
                             }
                         }
                     }
                 }
                 if (isset($optionRelations[$productId])) {
                     unset($optionRelations[$productId]);
                 }
                 $this->updateProductFlags($productId, $group->getAbsolutePrice(), $group->getAbsoluteWeight(), $group->getSkuPolicy());
             }
         }
         // remnants of the options that must be removed
         if (count($optionRelations) > 0) {
             foreach ($optionRelations as $productId => $prevOptions) {
                 if (count($prevOptions) > 0 && !in_array($productId, $productIds)) {
                     foreach ($prevOptions as $prevOption) {
                         $connection->delete($tablePrefix . 'catalog_product_option', 'option_id = ' . $prevOption['option_id']);
                         $connection->delete($tablePrefix . 'custom_options_option_view_mode', 'option_id = ' . $prevOption['option_id']);
                         $connection->delete($tablePrefix . 'custom_options_option_description', 'option_id = ' . $prevOption['option_id']);
                         $connection->delete($tablePrefix . 'custom_options_option_default', 'option_id = ' . $prevOption['option_id']);
                         $connection->delete($tablePrefix . 'custom_options_relation', 'group_id = ' . $templateId . ' AND product_id = ' . $productId . ' AND option_id = ' . $prevOption['option_id']);
                     }
                     $this->updateProductFlags($productId, $group->getAbsolutePrice(), $group->getAbsoluteWeight(), $group->getSkuPolicy());
                 }
             }
         }
     }
 }
 public function getOptionValues()
 {
     $data = array();
     $optionsArr = '';
     $data = $this->getTemplateData();
     if (isset($data['hash_options'])) {
         $optionsArr = $data['hash_options'];
     }
     $zendDate = new Zend_Date();
     $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
     $helper = Mage::helper('customoptions');
     $helper->getCustomerGroups();
     // init customer_groups for sort prices
     $groupId = (int) $this->getRequest()->getParam('group_id');
     if ($optionsArr) {
         $optionsArr = unserialize($optionsArr);
     }
     $store = Mage::app()->getStore($this->getStoreId());
     $storeOptionsArr = array();
     $groupStore = Mage::getSingleton('customoptions/group_store')->loadByGroupAndStore($groupId, $this->getStoreId());
     if ($groupStore->getHashOptions()) {
         $storeOptionsArr = unserialize($groupStore->getHashOptions());
     }
     //print_r($storeOptionsArr); exit;
     $optionModel = Mage::getSingleton('catalog/product_option');
     if (!$this->_values && $optionsArr) {
         $values = array();
         $sortOrder = array();
         $scope = (int) Mage::app()->getStore()->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE);
         $optionItemCount = count($optionsArr);
         foreach ($optionsArr as $optionId => $option) {
             $option = new Varien_Object($option);
             $value = array();
             if ($option->getIsDelete() != '1') {
                 $value['id'] = $option->getOptionId();
                 $value['item_count'] = $optionItemCount;
                 $value['option_id'] = $option->getOptionId();
                 $value['title'] = $this->htmlEscape(isset($storeOptionsArr[$optionId]['title']) ? $storeOptionsArr[$optionId]['title'] : $option->getTitle());
                 // old view_mode = hidden => to new type = 'hidden';
                 if ($optionModel->getGroupByType($option->getType()) == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT && $option->getViewMode() == 2) {
                     $option->setType('hidden');
                     $option->setViewMode(1);
                 }
                 $value['type'] = $option->getType();
                 $value['is_require'] = $option->getIsRequire();
                 $value['view_mode'] = isset($storeOptionsArr[$optionId]['view_mode']) ? $storeOptionsArr[$optionId]['view_mode'] : $option->getViewMode();
                 $value['is_dependent'] = $option->getIsDependent();
                 $value['div_class'] = $option->getDivClass();
                 $value['sku_policy'] = $option->getSkuPolicy();
                 $value['customoptions_is_onetime'] = $option->getCustomoptionsIsOnetime();
                 $value['qnty_input'] = $option->getQntyInput() ? 'checked' : '';
                 $value['qnty_input_disabled'] = $option->getType() == 'multiple' || $option->getType() == 'hidden' ? 'disabled' : '';
                 $value['image_mode'] = $option->getImageMode();
                 $value['image_mode_disabled'] = $optionModel->getGroupByType($option->getType()) != Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT ? 'disabled' : '';
                 $value['exclude_first_image'] = $option->getExcludeFirstImage() ? 'checked' : '';
                 $value['description'] = $this->htmlEscape(isset($storeOptionsArr[$optionId]['description']) ? $storeOptionsArr[$optionId]['description'] : $option->getDescription());
                 if ($helper->isCustomerGroupsEnabled() && $option->getCustomerGroups() != null) {
                     $value['customer_groups'] = implode(',', $option->getCustomerGroups());
                 }
                 if ($helper->isStoreViewsEnabled() && $option->getStoreViews() != null) {
                     $value['store_views'] = implode(',', $option->getStoreViews());
                 }
                 $value['in_group_id'] = $option->getInGroupId();
                 $value['in_group_id_view'] = $option->getInGroupId();
                 $value['sort_order'] = $this->_getSortOrder($option);
                 if ($this->getStoreId() != '0') {
                     $value['checkboxScopeTitle'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'title', !isset($storeOptionsArr[$optionId]['title']));
                     $value['scopeTitleDisabled'] = !isset($storeOptionsArr[$optionId]['title']) ? 'disabled' : null;
                     $value['checkboxScopeViewMode'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'view_mode', !isset($storeOptionsArr[$optionId]['view_mode']));
                     $value['scopeViewModeDisabled'] = !isset($storeOptionsArr[$optionId]['view_mode']) ? 'disabled' : null;
                     $value['checkboxScopeDescription'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'description', !isset($storeOptionsArr[$optionId]['description']));
                     $value['scopeDescriptionDisabled'] = !isset($storeOptionsArr[$optionId]['description']) ? 'disabled' : null;
                 }
                 if ($optionModel->getGroupByType($option->getType()) == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) {
                     $countValues = count($option->getValues());
                     if ($countValues > 0) {
                         foreach ($option->getValues() as $key => $_value) {
                             $_value = new Varien_Object($_value);
                             $_value->setOptionTypeId($key);
                             if ($_value->getIsDelete() != '1') {
                                 $defaultArray = $option->getDefault() !== null ? $option->getDefault() : array();
                                 if (isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price'])) {
                                     $_value->setPrice(floatval($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price']));
                                 }
                                 if (isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price_type'])) {
                                     $_value->setPriceType($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price_type']);
                                 }
                                 // for support old format:
                                 if (isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['special_price'])) {
                                     $_value->setSpecialPrice(floatval($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['special_price']));
                                 }
                                 if (isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['special_comment'])) {
                                     $_value->setSpecialComment($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['special_comment']);
                                 }
                                 if ($_value->getSpecialPrice()) {
                                     $_value->setSpecials(array(array('customer_group_id' => 32000, 'price' => $_value->getSpecialPrice(), 'price_type' => 'fixed', 'comment' => $_value->getSpecialComment(), 'date_from' => '', 'date_to' => '')));
                                 }
                                 $helper->applyLinkedBySkuDataToOption($_value, $_value->getSku(), $store, 0);
                                 $helper->calculateOptionSpecialPrice($_value, null, $helper->isSpecialPriceEnabled());
                                 $priceDisabled = $_value->getIsSkuPrice();
                                 list($skuClass, $viewProductBySkuHtml) = $this->getViewSkuData($_value->getSku());
                                 if (!$helper->isSkuQtyLinkingEnabled() || $helper->getProductIdBySku($_value->getSku()) == 0) {
                                     $customoptionsQty = $_value->getCustomoptionsQty();
                                 } else {
                                     list($customoptionsQty, $backorders) = $helper->getCustomoptionsQty($_value->getCustomoptionsQty(), $_value->getSku(), 0, null, null, null, true);
                                 }
                                 $value['optionValues'][$key] = array('item_count' => $countValues, 'option_id' => $option->getOptionId(), 'option_type_id' => $_value->getOptionTypeId(), 'title' => $this->htmlEscape(isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['title']) ? $storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['title'] : $_value->getTitle()), 'price' => $this->getPriceValue($_value->getPrice(), $_value->getPriceType()), 'price_type' => $_value->getPriceType(), 'price_disabled' => $priceDisabled, 'description' => $this->htmlEscape(isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['description']) ? $storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['description'] : $_value->getDescription()), 'cost' => $this->getPriceValue($_value->getCost(), 'fixed'), 'cost_disabled' => $_value->getIsSkuCost() ? 'disabled' : '', 'customoptions_qty' => $customoptionsQty, 'customoptions_qty_disabled' => $helper->isSkuQtyLinkingEnabled() && $helper->getProductIdBySku($_value->getSku()) ? 'disabled="disabled"' : '', 'sku' => $this->htmlEscape($_value->getSku()), 'sku_class' => $skuClass, 'view_product_by_sku_html' => $viewProductBySkuHtml, 'image_button_label' => $helper->__('Add Image'), 'sort_order' => $this->_getSortOrder($_value), 'checked' => array_search($_value->getOptionTypeId(), $defaultArray) !== false ? 'checked' : '', 'default_type' => $option->getType() == 'checkbox' || $option->getType() == 'multiple' || $option->getType() == 'multiswatch' || $option->getType() == 'hidden' ? 'checkbox' : 'radio', 'in_group_id' => $_value->getInGroupId(), 'in_group_id_view' => $_value->getInGroupId(), 'dependent_ids' => $_value->getDependentIds(), 'weight' => number_format(floatval($_value->getWeight()), 4, null, ''), 'weight_disabled' => $_value->getIsSkuWeight() ? 'disabled' : '');
                                 // getImages
                                 $images = $_value->getImages();
                                 if ($images) {
                                     $imagePath = $groupId . DS . $option->getId() . DS . $_value->getOptionTypeId() . DS;
                                     foreach ($images as $fileName) {
                                         if (substr($fileName, 0, 1) == '#') {
                                             // color
                                             $colorArr = array('id' => $option->getId(), 'select_id' => $_value->getOptionTypeId(), 'image_file' => $fileName, 'option_type_image_id' => $fileName, 'source' => 2);
                                             $value['optionValues'][$key]['images'][] = $colorArr;
                                         } else {
                                             // file
                                             $imgArr = $helper->getImgData($imagePath . $fileName, $option->getId(), $_value->getOptionTypeId());
                                             if ($imgArr) {
                                                 $imgArr['option_type_image_id'] = $imgArr['file_name'];
                                                 $value['optionValues'][$key]['images'][] = $imgArr;
                                             }
                                         }
                                     }
                                 } elseif ($_value->getImagePath()) {
                                     // old format
                                     $imgArr = $helper->getImgData($_value->getImagePath(), $option->getId(), $_value->getOptionTypeId());
                                     if ($imgArr) {
                                         $imgArr['option_type_image_id'] = $imgArr['file_name'];
                                         $value['optionValues'][$key]['images'][] = $imgArr;
                                     }
                                 } else {
                                     $value['optionValues'][$key]['image_tr_style'] = 'display:none';
                                 }
                                 //getOptionValueSpecialPrices
                                 $specialPrices = isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['specials']) ? $storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['specials'] : $_value->getSpecials();
                                 if ($specialPrices) {
                                     foreach ($specialPrices as $specialKey => $specialPrice) {
                                         $specialPrices[$specialKey]['price'] = $this->getPriceValue($specialPrice['price'], $specialPrice['price_type']);
                                         if (isset($specialPrice['date_from']) && $specialPrice['date_from']) {
                                             $specialPrices[$specialKey]['date_from'] = $zendDate->setDate($specialPrice['date_from'], Varien_Date::DATE_INTERNAL_FORMAT)->toString($dateFormat);
                                         } else {
                                             $specialPrices[$specialKey]['date_from'] = '';
                                         }
                                         if (isset($specialPrice['date_to']) && $specialPrice['date_to']) {
                                             $specialPrices[$specialKey]['date_to'] = $zendDate->setDate($specialPrice['date_to'], Varien_Date::DATE_INTERNAL_FORMAT)->toString($dateFormat);
                                         } else {
                                             $specialPrices[$specialKey]['date_to'] = '';
                                         }
                                     }
                                     usort($specialPrices, array($helper, '_sortPrices'));
                                     $value['optionValues'][$key]['specials'] = $specialPrices;
                                 }
                                 //getOptionValueTierPrices
                                 $tierPrices = isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['tiers']) ? $storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['tiers'] : $_value->getTiers();
                                 if ($tierPrices) {
                                     foreach ($tierPrices as $tierKey => $tierPrice) {
                                         $tierPrices[$tierKey]['price'] = $this->getPriceValue($tierPrice['price'], $tierPrice['price_type']);
                                     }
                                     usort($tierPrices, array($helper, '_sortPrices'));
                                     $value['optionValues'][$key]['tiers'] = $tierPrices;
                                 }
                                 if ($this->getStoreId() != '0') {
                                     $value['optionValues'][$key]['checkboxScopeTitle'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'title', !isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['title']), $_value->getOptionTypeId());
                                     $value['optionValues'][$key]['scopeTitleDisabled'] = !isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['title']) ? 'disabled' : null;
                                     $value['optionValues'][$key]['checkboxScopeDescription'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'description', !isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['description']), $_value->getOptionTypeId());
                                     $value['optionValues'][$key]['scopeDescriptionDisabled'] = !isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['description']) ? 'disabled' : null;
                                     //if ($scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE) {
                                     if (isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price'])) {
                                         $scopePrice = true;
                                     } else {
                                         $scopePrice = false;
                                     }
                                     if (!$priceDisabled) {
                                         $value['optionValues'][$key]['checkboxScopePrice'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'price', !$scopePrice, $_value->getOptionTypeId());
                                     }
                                     $value['optionValues'][$key]['scopePriceDisabled'] = !$scopePrice ? 'disabled' : null;
                                     //}
                                 }
                             }
                         }
                         $value['optionValues'] = array_values($value['optionValues']);
                     }
                 } else {
                     if (isset($storeOptionsArr[$optionId]['price'])) {
                         $option->setPrice(floatval($storeOptionsArr[$optionId]['price']));
                     }
                     if (isset($storeOptionsArr[$optionId]['price_type'])) {
                         $option->setPriceType($storeOptionsArr[$optionId]['price_type']);
                     }
                     $helper->applyLinkedBySkuDataToOption($option, $option->getSku(), $store, 0);
                     $helper->calculateOptionSpecialPrice($option, null, false);
                     $priceDisabled = $option->getIsSkuPrice();
                     list($skuClass, $viewProductBySkuHtml) = $this->getViewSkuData($option->getSku());
                     $value['price'] = $this->getPriceValue($option->getPrice(), $option->getPriceType());
                     $value['price_type'] = $option->getPriceType();
                     $value['price_disabled'] = $priceDisabled;
                     $value['sku'] = $this->htmlEscape($option->getSku());
                     $value['sku_class'] = $skuClass;
                     $value['view_product_by_sku_html'] = $viewProductBySkuHtml;
                     $value['max_characters'] = $option->getMaxCharacters();
                     $value['default_text'] = $this->htmlEscape(isset($storeOptionsArr[$optionId]['default_text']) ? $storeOptionsArr[$optionId]['default_text'] : $option->getDefaultText());
                     $value['file_extension'] = $option->getFileExtension();
                     $value['image_size_x'] = $option->getImageSizeX();
                     $value['image_size_y'] = $option->getImageSizeY();
                     $value['image_button_label'] = $helper->__('Add Image');
                     $imgHtml = $helper->getImgHtml($helper->getImgData($option->getImagePath(), $option->getId()));
                     if ($imgHtml) {
                         $value['image'] = $imgHtml;
                         $value['image_button_label'] = $helper->__('Change Image');
                     }
                     if ($this->getStoreId() != '0') {
                         //&& $scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE
                         if (!$priceDisabled) {
                             $value['checkboxScopePrice'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'price', !isset($storeOptionsArr[$optionId]['price']));
                         }
                         $value['scopePriceDisabled'] = !isset($storeOptionsArr[$optionId]['price']) ? 'disabled' : null;
                         $value['checkboxScopeDefaultText'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'default_text', !isset($storeOptionsArr[$optionId]['default_text']));
                         $value['scopeDefaultTextDisabled'] = !isset($storeOptionsArr[$optionId]['default_text']) ? 'disabled' : null;
                     }
                 }
                 $values[] = new Varien_Object($value);
             }
         }
         $this->_values = $values;
     }
     return $this->_values ? $this->_values : array();
 }