예제 #1
0
 public function importatteco()
 {
     // Add product attribute to economic
     $cnt = JRequest::getInt('cnt', 0);
     $totalprd = 0;
     $msg = '';
     if (ECONOMIC_INTEGRATION == 1 && ATTRIBUTE_AS_PRODUCT_IN_ECONOMIC == 1) {
         $economic = new economic();
         $db = JFactory::getDbo();
         $incNo = $cnt;
         $query = "SELECT ap.*, a.attribute_name, p.product_id, p.accountgroup_id " . "FROM #__redshop_product_attribute_property AS ap " . "LEFT JOIN #__redshop_product_attribute AS a ON a.attribute_id=ap.attribute_id " . "LEFT JOIN #__redshop_product AS p ON p.product_id=a.product_id " . "WHERE p.published=1 " . "AND p.product_id!='' " . "AND ap.property_number!='' " . "LIMIT " . $cnt . ", 10 ";
         $db->setQuery($query);
         $list = $db->loadObjectlist();
         $totalprd = count($list);
         $responcemsg = '';
         for ($i = 0; $i < count($list); $i++) {
             $incNo++;
             $prdrow = new stdClass();
             $prdrow->product_id = $list[$i]->product_id;
             $prdrow->accountgroup_id = $list[$i]->accountgroup_id;
             $ecoProductNumber = $economic->createPropertyInEconomic($prdrow, $list[$i]);
             $responcemsg .= "<div>" . $incNo . ": " . JText::_('COM_REDSHOP_PROPERTY_NUMBER') . " " . $list[$i]->property_number . " -> ";
             if (count($ecoProductNumber) > 0 && is_object($ecoProductNumber[0]) && isset($ecoProductNumber[0]->Number)) {
                 $responcemsg .= "<span style='color: #00ff00'>" . JText::_('COM_REDSHOP_IMPORT_ATTRIBUTES_TO_ECONOMIC_SUCCESS') . "</span>";
             } else {
                 $errmsg = JText::_('COM_REDSHOP_ERROR_IN_IMPORT_ATTRIBUTES_TO_ECONOMIC');
                 if (JError::isError(JError::getError())) {
                     $error = JError::getError();
                     $errmsg = $error->message;
                 }
                 $responcemsg .= "<span style='color: #ff0000'>" . $errmsg . "</span>";
             }
             $responcemsg .= "</div>";
         }
         $query = "SELECT sp.*, ap.property_id, ap.property_name, p.product_id, p.accountgroup_id  FROM #__redshop_product_subattribute_color AS sp " . "LEFT JOIN #__redshop_product_attribute_property AS ap ON ap.property_id=sp.subattribute_id " . "LEFT JOIN #__redshop_product_attribute AS a ON a.attribute_id=ap.attribute_id " . "LEFT JOIN #__redshop_product AS p ON p.product_id=a.product_id " . "WHERE p.published=1 " . "AND p.product_id!='' " . "AND sp.subattribute_color_number!='' " . "LIMIT " . $cnt . ", 10 ";
         $db->setQuery($query);
         $list = $db->loadObjectlist();
         $totalprd = $totalprd + count($list);
         for ($i = 0; $i < count($list); $i++) {
             $incNo++;
             $prdrow = new stdClass();
             $prdrow->product_id = $list[$i]->product_id;
             $prdrow->accountgroup_id = $list[$i]->accountgroup_id;
             $ecoProductNumber = $economic->createSubpropertyInEconomic($prdrow, $list[$i]);
             $responcemsg .= "<div>" . $incNo . ": " . JText::_('COM_REDSHOP_SUBPROPERTY_NUMBER') . " " . $list[$i]->subattribute_color_number . " -> ";
             if (count($ecoProductNumber) > 0 && is_object($ecoProductNumber[0]) && isset($ecoProductNumber[0]->Number)) {
                 $responcemsg .= "<span style='color: #00ff00'>" . JText::_('COM_REDSHOP_IMPORT_ATTRIBUTES_TO_ECONOMIC_SUCCESS') . "</span>";
             } else {
                 $errmsg = JText::_('COM_REDSHOP_ERROR_IN_IMPORT_ATTRIBUTES_TO_ECONOMIC');
                 if (JError::isError(JError::getError())) {
                     $error = JError::getError();
                     $errmsg = $error->message;
                 }
                 $responcemsg .= "<span style='color: #ff0000'>" . $errmsg . "</span>";
             }
             $responcemsg .= "</div>";
         }
         if ($totalprd > 0) {
             $msg = $responcemsg;
         } else {
             $msg = JText::_("COM_REDSHOP_IMPORT_ATTRIBUTES_TO_ECONOMIC_IS_COMPLETED");
         }
     }
     echo "<div id='sentresponse'>" . $totalprd . "`_`" . $msg . "</div>";
     die;
 }
예제 #2
0
 /**
  * Function attribute_save.
  *
  * @param   array   $post  Array of input data.
  * @param   object  $row   Array of row data.
  *
  * @return void
  */
 public function attribute_save($post, $row)
 {
     $economic = null;
     if (ECONOMIC_INTEGRATION == 1 && ATTRIBUTE_AS_PRODUCT_IN_ECONOMIC != 0) {
         $economic = new economic();
     }
     $model = $this->getModel('product_detail');
     $attribute_save = array();
     $property_save = array();
     $subproperty_save = array();
     if (!is_array($post['attribute'])) {
         return;
     }
     $attribute = array_merge(array(), $post['attribute']);
     for ($a = 0; $a < count($attribute); $a++) {
         $attribute_save['attribute_id'] = $attribute[$a]['id'];
         $tmpordering = $attribute[$a]['tmpordering'] ? $attribute[$a]['tmpordering'] : $a;
         $attribute_save['product_id'] = $row->product_id;
         $attribute_save['attribute_name'] = urldecode($attribute[$a]['name']);
         $attribute_save['ordering'] = $attribute[$a]['ordering'];
         $attribute_save['attribute_published'] = $attribute[$a]['published'] == 'on' || $attribute[$a]['published'] == '1' ? '1' : '0';
         $attribute_save['attribute_required'] = $attribute[$a]['required'] == 'on' || $attribute[$a]['required'] == '1' ? '1' : '0';
         $attribute_save['allow_multiple_selection'] = $attribute[$a]['allow_multiple_selection'] == 'on' || $attribute[$a]['allow_multiple_selection'] == '1' ? '1' : '0';
         $attribute_save['hide_attribute_price'] = $attribute[$a]['hide_attribute_price'] == 'on' || $attribute[$a]['hide_attribute_price'] == '1' ? '1' : '0';
         $attribute_save['display_type'] = $attribute[$a]['display_type'];
         $attribute_array = $model->store_attr($attribute_save);
         $property = array_merge(array(), $attribute[$a]['property']);
         $propertyImage = array_keys($attribute[$a]['property']);
         $tmpproptyimagename = array_merge(array(), $propertyImage);
         for ($p = 0; $p < count($property); $p++) {
             $property_save['property_id'] = $property[$p]['property_id'];
             $property_save['attribute_id'] = $attribute_array->attribute_id;
             $property_save['property_name'] = urldecode($property[$p]['name']);
             $property_save['property_price'] = $property[$p]['price'];
             $property_save['oprand'] = $property[$p]['oprand'];
             $property_save['property_number'] = $property[$p]['number'];
             $property_save['property_image'] = $property[$p]['image'];
             $property_save['ordering'] = $property[$p]['order'];
             $property_save['setrequire_selected'] = $property[$p]['req_sub_att'] == 'on' || $property[$p]['req_sub_att'] == '1' ? '1' : '0';
             $property_save['setmulti_selected'] = $property[$p]['multi_sub_att'] == 'on' || $property[$p]['multi_sub_att'] == '1' ? '1' : '0';
             $property_save['setdefault_selected'] = $property[$p]['default_sel'] == 'on' || $property[$p]['default_sel'] == '1' ? '1' : '0';
             $property_save['setdisplay_type'] = $property[$p]['setdisplay_type'];
             $property_save['property_published'] = $property[$p]['published'] == 'on' || $property[$p]['published'] == '1' ? '1' : '0';
             $property_save['extra_field'] = $property[$p]['extra_field'];
             $property_array = $model->store_pro($property_save);
             $property_id = $property_array->property_id;
             $property_image = $this->input->files->get('attribute_' . $tmpordering . '_property_' . $tmpproptyimagename[$p] . '_image', array(), 'array');
             if (empty($property[$p]['mainImage'])) {
                 if (!empty($property_image['name'])) {
                     $property_save['property_image'] = $model->copy_image($property_image, 'product_attributes', $property_id);
                     $property_save['property_id'] = $property_id;
                     $property_array = $model->store_pro($property_save);
                     $this->DeleteMergeImages();
                 }
             }
             if (!empty($property[$p]['mainImage'])) {
                 $property_save['property_image'] = $model->copy_image_from_path($property[$p]['mainImage'], 'product_attributes');
                 $property_save['property_id'] = $property_id;
                 $property_array = $model->store_pro($property_save);
                 $this->DeleteMergeImages();
             }
             if (empty($property[$p]['property_id'])) {
                 $listImages = $model->GetimageInfo($property_id, 'property');
                 for ($li = 0; $li < count($listImages); $li++) {
                     $mImages = array();
                     $mImages['media_name'] = $listImages[$li]->media_name;
                     $mImages['media_alternate_text'] = $listImages[$li]->media_alternate_text;
                     $mImages['media_section'] = 'property';
                     $mImages['section_id'] = $property_id;
                     $mImages['media_type'] = 'images';
                     $mImages['media_mimetype'] = $listImages[$li]->media_mimetype;
                     $mImages['published'] = $listImages[$li]->published;
                     $model->copyadditionalImage($mImages);
                 }
             }
             if (ECONOMIC_INTEGRATION == 1 && ATTRIBUTE_AS_PRODUCT_IN_ECONOMIC != 0) {
                 $economic->createPropertyInEconomic($row, $property_array);
             }
             // Set trigger to save Attribute Property Plugin Data
             if ((int) $property_id) {
                 $dispatcher = JDispatcher::getInstance();
                 JPluginHelper::importPlugin('redshop_product_type');
                 // Trigger the data preparation event.
                 $dispatcher->trigger('onAttributePropertySaveLoop', array($row, &$property[$p], &$property_array));
             }
             $subproperty = array_merge(array(), $property[$p]['subproperty']);
             $subproperty_title = $property[$p]['subproperty']['title'];
             $subpropertyImage = array_keys($property[$p]['subproperty']);
             unset($subpropertyImage[0]);
             $tmpimagename = array_merge(array(), $subpropertyImage);
             for ($sp = 0; $sp < count($subproperty) - 1; $sp++) {
                 $subproperty_save['subattribute_color_id'] = $subproperty[$sp]['subproperty_id'];
                 $subproperty_save['subattribute_color_name'] = $subproperty[$sp]['name'];
                 $subproperty_save['subattribute_color_title'] = $subproperty_title;
                 $subproperty_save['subattribute_color_price'] = $subproperty[$sp]['price'];
                 $subproperty_save['oprand'] = $subproperty[$sp]['oprand'];
                 $subproperty_save['subattribute_color_image'] = $subproperty[$sp]['image'];
                 $subproperty_save['subattribute_id'] = $property_id;
                 $subproperty_save['ordering'] = $subproperty[$sp]['order'];
                 $subproperty_save['subattribute_color_number'] = $subproperty[$sp]['number'];
                 $subproperty_save['setdefault_selected'] = $subproperty[$sp]['chk_propdselected'] == 'on' || $subproperty[$sp]['chk_propdselected'] == '1' ? '1' : '0';
                 $subproperty_save['subattribute_published'] = $subproperty[$sp]['published'] == 'on' || $subproperty[$sp]['published'] == '1' ? '1' : '0';
                 $subproperty_save['extra_field'] = $subproperty[$sp]['extra_field'];
                 $subproperty_array = $model->store_sub($subproperty_save);
                 $subproperty_image = $this->input->files->get('attribute_' . $tmpordering . '_property_' . $p . '_subproperty_' . $tmpimagename[$sp] . '_image', array(), 'array');
                 $subproperty_id = $subproperty_array->subattribute_color_id;
                 if (empty($subproperty[$sp]['mainImage'])) {
                     if (!empty($subproperty_image['name'])) {
                         $subproperty_save['subattribute_color_image'] = $model->copy_image($subproperty_image, 'subcolor', $subproperty_id);
                         $subproperty_save['subattribute_color_id'] = $subproperty_id;
                         $subproperty_array = $model->store_sub($subproperty_save);
                         $this->DeleteMergeImages();
                     }
                 }
                 if (!empty($subproperty[$sp]['mainImage'])) {
                     $subproperty_save['subattribute_color_image'] = $model->copy_image_from_path($subproperty[$sp]['mainImage'], 'subcolor');
                     $subproperty_save['subattribute_color_id'] = $subproperty_id;
                     $subproperty_array = $model->store_sub($subproperty_save);
                     $this->DeleteMergeImages();
                 }
                 if (empty($subproperty[$sp]['subproperty_id'])) {
                     $listsubpropImages = $model->GetimageInfo($subproperty_id, 'subproperty');
                     for ($lsi = 0; $lsi < count($listsubpropImages); $lsi++) {
                         $smImages = array();
                         $smImages['media_name'] = $listsubpropImages[$lsi]->media_name;
                         $smImages['media_alternate_text'] = $listsubpropImages[$lsi]->media_alternate_text;
                         $smImages['media_section'] = 'subproperty';
                         $smImages['section_id'] = $subproperty_id;
                         $smImages['media_type'] = 'images';
                         $smImages['media_mimetype'] = $listsubpropImages[$lsi]->media_mimetype;
                         $smImages['published'] = $listsubpropImages[$lsi]->published;
                         $model->copyadditionalImage($smImages);
                     }
                 }
                 if (ECONOMIC_INTEGRATION == 1 && ATTRIBUTE_AS_PRODUCT_IN_ECONOMIC != 0) {
                     $economic->createSubpropertyInEconomic($row, $subproperty_array);
                 }
             }
         }
     }
     return;
 }