コード例 #1
0
 public static function saveAll($data, $product_id)
 {
     if (empty($data['group_id'])) {
         return false;
     }
     $i = 0;
     $attrs = new Doctrine_Collection('ProductsAttributesIndexes');
     self::deleteAll($product_id);
     // Get all the product attributes
     $attributes = ProductsAttributesGroups::getAttributesProfiles($data['group_id']);
     // Loop of the posted variables
     foreach ($data as $var => $value) {
         // Loop of all the attributes
         foreach ($attributes as $attribute) {
             if ($attribute['ProductsAttributes']['code'] == $var) {
                 $attrs[$i]->product_id = $product_id;
                 $attrs[$i]->attribute_id = $attribute['attribute_id'];
                 $attrs[$i]->value = $value;
                 $i++;
             }
         }
     }
     $attrs->save();
 }
コード例 #2
0
 /**
  * Create the attribute elements
  * 
  * 
  * @param integer $attribute_group_id
  */
 private function createAttributesElements($form, $group_id)
 {
     $attributeForm = new Zend_Form_SubForm();
     $attributeForm->addElementPrefixPath('Shineisp_Decorator', 'Shineisp/Decorator/', 'decorator');
     if (is_numeric($group_id)) {
         // Get all the elements
         $elements = ProductsAttributesGroups::getAttributesProfiles($group_id, $this->session->langid);
         if (!empty($elements[0])) {
             foreach ($elements as $element) {
                 if (!empty($element['ProductsAttributes'])) {
                     // Check the label
                     $label = !empty($element['ProductsAttributes']['ProductsAttributesData'][0]['label']) ? $element['ProductsAttributes']['ProductsAttributesData'][0]['label'] : $element['ProductsAttributes']['code'];
                     $description = !empty($element['ProductsAttributes']['ProductsAttributesData'][0]['description']) ? $element['ProductsAttributes']['ProductsAttributesData'][0]['description'] : "";
                     // Create the element
                     $attributeForm->addElement($element['ProductsAttributes']['type'], $element['ProductsAttributes']['code'], array('label' => $label, 'class' => 'form-control', 'decorators' => array('Composite'), 'description' => $description));
                     if ($element['ProductsAttributes']['is_required']) {
                         $attributeForm->getElement($element['ProductsAttributes']['code'])->setRequired(true);
                     }
                     // Handle the default option items for the dropdown selector
                     if ($element['ProductsAttributes']['type'] == "select") {
                         $data = !empty($element['ProductsAttributes']['defaultvalue']) ? json_decode($element['ProductsAttributes']['defaultvalue'], true) : array();
                         $attributeForm->getElement($element['ProductsAttributes']['code'])->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions($data);
                     } else {
                         $attributeForm->getElement($element['ProductsAttributes']['code'])->setValue($element['ProductsAttributes']['defaultvalue']);
                     }
                 }
             }
             $form->addSubForm($attributeForm, 'attributes');
         }
     }
     return $form;
 }