Esempio n. 1
0
 protected function addProductCustomizationData(array $product_full)
 {
     if ($product_full['customizable']) {
         $customizationData = array('fields' => array());
         $customized_data = array();
         $already_customized = $this->context->cart->getProductCustomization($product_full['id_product'], null, true);
         $id_customization = 0;
         foreach ($already_customized as $customization) {
             $id_customization = $customization['id_customization'];
             $customized_data[$customization['index']] = $customization;
         }
         $customization_fields = $this->product->getCustomizationFields($this->context->language->id);
         if (is_array($customization_fields)) {
             foreach ($customization_fields as $customization_field) {
                 // 'id_customization_field' maps to what is called 'index'
                 // in what Product::getProductCustomization() returns
                 $key = $customization_field['id_customization_field'];
                 $field['label'] = $customization_field['name'];
                 $field['id_customization_field'] = $customization_field['id_customization_field'];
                 $field['required'] = $customization_field['required'];
                 switch ($customization_field['type']) {
                     case Product::CUSTOMIZE_FILE:
                         $field['type'] = 'image';
                         $field['image'] = null;
                         $field['input_name'] = 'file' . $customization_field['id_customization_field'];
                         break;
                     case Product::CUSTOMIZE_TEXTFIELD:
                         $field['type'] = 'text';
                         $field['text'] = '';
                         $field['input_name'] = 'textField' . $customization_field['id_customization_field'];
                         break;
                     default:
                         $field['type'] = null;
                 }
                 if (array_key_exists($key, $customized_data)) {
                     $data = $customized_data[$key];
                     $field['is_customized'] = true;
                     switch ($customization_field['type']) {
                         case Product::CUSTOMIZE_FILE:
                             $imageRetriever = new ImageRetriever($this->context->link);
                             $field['image'] = $imageRetriever->getCustomizationImage($data['value']);
                             $field['remove_image_url'] = $this->context->link->getProductDeletePictureLink($product_full, $customization_field['id_customization_field']);
                             break;
                         case Product::CUSTOMIZE_TEXTFIELD:
                             $field['text'] = $data['value'];
                             break;
                     }
                 } else {
                     $field['is_customized'] = false;
                 }
                 $customizationData['fields'][] = $field;
             }
         }
         $product_full['customizations'] = $customizationData;
         $product_full['id_customization'] = $id_customization;
         $product_full['is_customizable'] = true;
     } else {
         $product_full['customizations'] = array('fields' => array());
         $product_full['id_customization'] = 0;
         $product_full['is_customizable'] = false;
     }
     return $product_full;
 }
Esempio n. 2
0
 public function getTemplateVarCustomization(array $product)
 {
     $product_customizations = array();
     $imageRetriever = new ImageRetriever($this->context->link);
     foreach ($product['customizedDatas'] as $byAddress) {
         foreach ($byAddress as $customization) {
             $presentedCustomization = array('quantity' => $customization['quantity'], 'fields' => array(), 'id_customization' => null);
             foreach ($customization['datas'] as $byType) {
                 $field = array();
                 foreach ($byType as $data) {
                     switch ($data['type']) {
                         case Product::CUSTOMIZE_FILE:
                             $field['type'] = 'image';
                             $field['image'] = $imageRetriever->getCustomizationImage($data['value']);
                             break;
                         case Product::CUSTOMIZE_TEXTFIELD:
                             $field['type'] = 'text';
                             $field['text'] = $data['value'];
                             break;
                         default:
                             $field['type'] = null;
                     }
                     $field['label'] = $data['name'];
                     $field['id_module'] = $data['id_module'];
                     $presentedCustomization['id_customization'] = $data['id_customization'];
                 }
                 $presentedCustomization['fields'][] = $field;
             }
             $product_customizations[] = $presentedCustomization;
         }
     }
     return $product_customizations;
 }