Exemple #1
0
 public function getOptionArray(Mage_Catalog_Model_Product_Option $option)
 {
     $commonArgs = array('is_delete', 'previous_type', 'previous_group', 'title', 'type', 'is_require', 'sort_order', 'values');
     $priceArgs = array('price_type', 'price', 'sku');
     $txtArgs = array('max_characters');
     $fileArgs = array('file_extension', 'image_size_x', 'image_size_y');
     $multiArgs = array('is_delete', 'title', 'sort_order');
     $multi = array('drop_down', 'radio', 'checkbox', 'multiple');
     $valueArgs = array_merge($multiArgs, $priceArgs);
     $type = $option->getType();
     switch ($type) {
         case 'file':
             $optionArgs = array_merge($commonArgs, $priceArgs, $fileArgs);
             break;
         case 'field':
         case 'area':
             $optionArgs = array_merge($commonArgs, $priceArgs, $txtArgs);
             break;
         case 'date':
         case 'date_time':
         case 'time':
             $optionArgs = array_merge($commonArgs, $priceArgs);
             break;
         default:
             $optionArgs = $commonArgs;
             break;
     }
     $optionArray = $option->toArray($optionArgs);
     if (in_array($type, $multi)) {
         $optionArray['values'] = array();
         foreach ($option->getValues() as $value) {
             $optionArray['values'][] = $value->toArray($valueArgs);
         }
     }
     return $optionArray;
 }
Exemple #2
0
 /**
  * Get all custom option values prices
  *
  * @param Mage_Catalog_Model_Product_Option $option
  * @return array
  */
 protected function _getCustomOptionValuesPrices($option)
 {
     $values = $option->getValues();
     $prices = array();
     if ($values) {
         foreach ($values as $value) {
             /* @var $value Mage_Catalog_Model_Product_Option_Value */
             $prices[] = $value->getPrice(true);
         }
     }
     return $prices;
 }
Exemple #3
0
 /**
  * Retrieve option values or false for options which has no values
  *
  * @param Mage_Catalog_Model_Product_Option $option
  * @return array|bool
  */
 protected function _getOptionValues(Mage_Catalog_Model_Product_Option $option)
 {
     $values = $option->getValues();
     if (!empty($values)) {
         $result = array();
         /** @var $value Mage_Catalog_Model_Product_Option_Value */
         foreach ($values as $value) {
             $optionData = array();
             foreach ($this->_assertOptionValues as $assertKey) {
                 if ($value->hasData($assertKey)) {
                     $optionData[$assertKey] = $value->getData($assertKey);
                 }
             }
             $result[] = $optionData;
         }
         return $result;
     }
     return false;
 }
Exemple #4
0
 /**
  * Check whether required option is not missed, add values to configuration
  *
  * @param array $skuParts
  * @param Mage_Catalog_Model_Product_Option $option
  * @return bool
  */
 protected function _processProductOption(array &$skuParts, Mage_Catalog_Model_Product_Option $option)
 {
     $missedRequired = true;
     $optionValues = $option->getValues();
     if (empty($optionValues)) {
         if ($option->hasSku()) {
             $found = array_search($option->getSku(), $skuParts);
             if ($found !== false) {
                 unset($skuParts[$found]);
             }
         }
         // we are not able to configure such option automatically
         return !$missedRequired;
     }
     foreach ($optionValues as $optionValue) {
         $found = array_search($optionValue->getSku(), $skuParts);
         if ($found !== false) {
             $this->_addSuccessOption($option, $optionValue);
             unset($skuParts[$found]);
             // we've found the value of required option
             $missedRequired = false;
             if (!$this->_isOptionMultiple($option)) {
                 break 1;
             }
         }
     }
     return !$missedRequired;
 }