Exemplo n.º 1
0
 function _subProductsFields($types, $prefix = 'ShopSubproduct.')
 {
     App::import('Lib', 'Shop.SetMulti');
     $config = ShopConfig::load();
     $typeFields = array();
     if (!empty($types)) {
         foreach ($types as $key => $type) {
             $fields = set::normalize(array('id', 'code', 'label_fre', 'label_eng', 'operator', 'price'));
             if (isset($type['price']) && $type['price'] === false) {
                 unset($fields['price']);
                 unset($fields['operator']);
             }
             if (array_key_exists('price', $fields) && !empty($config['currencies'])) {
                 //$fields['price']['label'] = __('Default Price',true);
                 unset($fields['price']);
                 foreach ($config['currencies'] as $currency) {
                     $fOpt = array('label' => str_replace('%currency%', $currency, __('Price %currency%', true)), 'type' => 'text');
                     $fields['currency_prices.' . $currency] = $fOpt;
                 }
             }
             if (array_key_exists('operator', $fields)) {
                 if (count($type['operators']) == 1) {
                     $fields = SetMulti::insertBeforeKey($fields, 'operator', array('operator_display' => array('type' => 'definition', 'value' => $type['operators'][0], 'label' => __('Operator', true))));
                     $fields['operator']['type'] = 'hidden';
                     $fields['operator']['value'] = $type['operators'][0];
                 } else {
                     $fields['operator']['options'] = $type['operators'];
                 }
                 if (isset($type['adminFields'])) {
                     $fields = set::merge($fields, $type['adminFields']);
                 }
             }
             $typeField = array('type' => 'multiple', 'fields' => $fields, 'div' => array('class' => 'type'));
             if (!empty($type['children'])) {
                 $typeField['subline'] = $this->_subProductsFields($type['children'], 'children.');
             }
             $typeFields[$prefix . $key] = $typeField;
         }
     }
     return $typeFields;
 }