Пример #1
0
    protected function displaySortCriteriaPanel($objCrit = false)
    {
        if (Tools::getValue('pm_load_function') != 'displaySortCriteriaPanel') {
            $this->_html .= '<div id="sortCriteriaPanel">';
        } else {
            $objCrit = new AdvancedSearchCriterionGroupClass(Tools::getValue('id_criterion_group'), Tools::getValue('id_search'));
            if (Tools::getValue('sort_way')) {
                $objCrit->sort_by = Tools::getValue('sort_by');
                $objCrit->sort_way = Tools::getValue('sort_way');
                $objCrit->save();
                $msgConfirm = $this->l('Specific sort apply');
                if ($objCrit->sort_by == 'position') {
                    $msgConfirm .= '<br />' . $this->l('Now, you can sort criteria by drag n drop');
                }
                $this->_html .= '<script type="text/javascript">show_info("' . addcslashes($msgConfirm, '"') . '");</script>';
            }
        }
        $criterions = AdvancedSearchClass::getCriterionsFromCriterionGroup($objCrit->criterion_group_type, $objCrit->id_criterion_group_linked, $objCrit->id_search, $objCrit->sort_by, $objCrit->sort_way, $this->_cookie->id_lang);
        $this->_html .= '
		<div class="clear"></div>
		<div class="criterionGroupActions">
			<ul>
				<li><a href="' . $this->_base_config_url . '&pm_load_function=processEnableAllCriterions&id_criterion_group=' . $objCrit->id . '&id_search=' . $objCrit->id_search . '" class="ajax_script_load activeAllCriterions" title="' . $this->l('Activate all criterions') . '">' . $this->l('Activate all criterions') . '</a></li>
				<li><a href="' . $this->_base_config_url . '&pm_load_function=processDisableAllCriterions&id_criterion_group=' . $objCrit->id . '&id_search=' . $objCrit->id_search . '" class="ajax_script_load disableAllCriterions" title="' . $this->l('Disable all criterions') . '">' . $this->l('Disable all criterions') . '</a></li>
			</ul>
		</div>
		';
        $this->_html .= '<div class="clear"></div><ul class="sortableCriterion" id="sortableCriterion_' . (int) $objCrit->id_criterion_group_linked . '">';
        foreach ($criterions as $row) {
            $objCritClass = new AdvancedSearchCriterionClass($row['id_criterion'], $objCrit->id_search);
            $this->_html .= '<li class="ui-state-highlight' . (isset($row['is_custom']) && $row['is_custom'] ? ' customCriterionLi' : '') . '" id="criterion_' . $row['id_criterion'] . '" style="height:30px;">';
            $this->_html .= '<span class="ui-icon ui-icon-arrow-4-diag dragIcon dragIconCriterion" style="float:left;margin:0!important;' . ($objCrit->sort_by == 'position' ? '' : ' visibility:hidden') . '">
							</span>';
            $this->_html .= '<span class="critName">' . $row['value'] . '</span>';
            if ($objCrit->display_type == 2) {
                $this->_html .= '<div class="criterionImageContainer">';
                $this->_html .= '<form class="criterionForm" action="' . $this->_base_config_url . '" method="post" enctype="multipart/form-data" target="dialogIframePostForm">';
                $this->displayInlineUploadFile($objCritClass, 'icon' . $row['id_criterion'], 'icon', $this->l('Image'), '/search_files/criterions/');
                $this->_html .= '<input name="id_search" value="' . (int) $objCrit->id_search . '" type="hidden" />';
                $this->_html .= '<input name="id_criterion" value="' . (int) $row['id_criterion'] . '" type="hidden" />';
                $this->_html .= '<input name="key_criterions_group" value="' . $objCrit->criterion_group_type . '-' . (int) $objCrit->id_criterion_group_linked . '-' . (int) $objCrit->id_search . '" type="hidden" />';
                $this->_html .= '<a href="' . $this->_base_config_url . '&pm_load_function=processActiveCriterion&id_criterion=' . $row['id_criterion'] . '&id_search=' . $objCrit->id_search . '" class="ajax_script_load activeCriterion">
									<img src="../img/admin/' . ($row['visible'] ? 'enabled' : 'disabled') . '.gif" id="imgActiveCriterion' . $row['id_criterion'] . '" class="imgActiveCrit" />
								</a>';
                $this->_html .= '</form>';
                $this->_html .= '</div>';
            } else {
                if ($objCrit->criterion_group_type == 'attribute' && AdvancedSearchClass::isColorAttributesGroup($objCrit->id_criterion_group_linked) && isset($row['is_custom']) && $row['is_custom']) {
                    $this->_html .= '<div class="criterionCustomLiveEditContainer" data-id-criterion="' . (int) $row['id_criterion'] . '" data-id-search="' . (int) $objCrit->id_search . '">';
                    $this->_html .= '<div class="criterionCustomLiveField">';
                    $this->_displayInputTextLang(array('obj' => $objCritClass, 'key' => 'value', 'label' => $this->l('Criterion label:')));
                    $this->_html .= '</div>';
                    $this->_html .= '<div class="criterionCustomLiveField">';
                    $this->_displayInputColor(array('obj' => $objCritClass, 'key' => 'color', 'label' => $this->l('Color:')));
                    $this->_html .= '</div>';
                    $this->_html .= '<div style="float: right;">';
                    $this->_displaySubmit($this->l('Save'), 'submitCustomCriterionForm');
                    $this->_html .= '</div>';
                    $this->_html .= '</div>';
                    $this->_html .= '<a href="' . $this->_base_config_url . '&pm_load_function=processActiveCriterion&id_criterion=' . $row['id_criterion'] . '&id_search=' . $objCrit->id_search . '" class="ajax_script_load activeCriterion"><img src="../img/admin/' . ($row['visible'] ? 'enabled' : 'disabled') . '.gif" id="imgActiveCriterion' . $row['id_criterion'] . '" /></a>';
                    $this->_html .= '<a href="javascript:void(0)" class="editCustomCriterion"><img src="../img/admin/edit.gif" id="imgEditCriterion' . $row['id_criterion'] . '" class="imgEditCriterion" /></a>';
                    $this->_html .= '<a href="' . $this->_base_config_url . '&pm_load_function=processDeleteCustomCriterion&id_criterion=' . $row['id_criterion'] . '&id_search=' . $objCrit->id_search . '" class="ajax_script_load deleteCustomCriterion"><img src="../img/admin/delete.gif" id="imgDeleteCriterion' . $row['id_criterion'] . '" class="imgDeleteCriterion" /></a>';
                } else {
                    if ($objCrit->criterion_group_type == 'attribute' && AdvancedSearchClass::isColorAttributesGroup($objCrit->id_criterion_group_linked) && (!isset($row['is_custom']) || isset($row['is_custom']) && !$row['is_custom'])) {
                        $this->_html .= '<a href="' . $this->_base_config_url . '&pm_load_function=processActiveCriterion&id_criterion=' . $row['id_criterion'] . '&id_search=' . $objCrit->id_search . '" class="ajax_script_load activeCriterion"><img src="../img/admin/' . ($row['visible'] ? 'enabled' : 'disabled') . '.gif" id="imgActiveCriterion' . $row['id_criterion'] . '" /></a>';
                        $customCriterionsList = AdvancedSearchCriterionClass::getCustomCriterions($objCrit->id_search, $objCrit->id, $this->_cookie->id_lang);
                        $customCriterionsIdsList = AdvancedSearchCriterionClass::getCustomMasterIdCriterion((int) $objCrit->id_search, $row['id_criterion']);
                        if (is_array($customCriterionsList) && sizeof($customCriterionsList)) {
                            $customCriterionsList = array(0 => $this->l('None')) + $customCriterionsList;
                            $this->_html .= '<div class="addCriterionToCustomGroupContainer">';
                            $this->_displaySelect(array('obj' => (object) array('custom_group_link_id_' . (int) $row['id_criterion'] => AdvancedSearchCriterionClass::getCustomMasterIdCriterion((int) $objCrit->id_search, $row['id_criterion'])), 'label' => $this->l('Add to a group of custom criterion:'), 'key' => 'custom_group_link_id_' . (int) $row['id_criterion'], 'options' => $customCriterionsList, 'defaultvalue' => false, 'onchange' => 'processAddCustomCriterionToGroup($jqPm(this), ' . (int) $objCrit->id_search . ', ' . (int) Tools::getValue('id_criterion_group') . ')'));
                            $this->_html .= '</div>';
                        }
                    } else {
                        $this->_html .= '<a href="' . $this->_base_config_url . '&pm_load_function=processActiveCriterion&id_criterion=' . $row['id_criterion'] . '&id_search=' . $objCrit->id_search . '" class="ajax_script_load activeCriterion"><img src="../img/admin/' . ($row['visible'] ? 'enabled' : 'disabled') . '.gif" id="imgActiveCriterion' . $row['id_criterion'] . '" /></a>';
                    }
                }
            }
            $this->_html .= '</li>';
        }
        $this->_html .= '</ul>';
        if ($objCrit->sort_by == 'position') {
            $this->_html .= '<script type="text/javascript">$jqPm("#sortableCriterion_' . (int) $objCrit->id_criterion_group_linked . '").sortable({
					        handle : ".dragIconCriterion",
					                update: function(event, ui) {
					           var order = $jqPm(this).sortable("toArray");
					                saveOrder(order.join(","),"orderCriterion",' . (int) $objCrit->id_search . ');
					              }
					      });</script>';
        }
        if (Tools::getValue('pm_load_function') != 'displaySortCriteriaPanel') {
            $this->_html .= '</div>';
        }
    }
Пример #2
0
 public static function indexCriterionsGroup($criterions_group_type, $id_criterion_group_linked, $objSearch, $visible = 1, $checkIfIsIndexed = true, $update = false, $id_product = false, $id_criterion_linked = false, $criterion_value = false)
 {
     global $cookie;
     $objSearch->updateCacheProduct();
     if ($checkIfIsIndexed && self::criterionsGroupIsIndexed($criterions_group_type, $id_criterion_group_linked, $objSearch->id)) {
         self::desIndexCriterionsGroup($criterions_group_type, $id_criterion_group_linked, $objSearch->id, true, true);
     }
     $id_criterion_group = false;
     if ($update) {
         $id_criterion_group = AdvancedSearchCriterionGroupClass::getIdCriterionGroupByTypeAndIdLinked($objSearch->id, $criterions_group_type, $id_criterion_group_linked);
         if (!$id_criterion_group) {
             return;
         }
         if (!$id_product) {
             if ($criterions_group_type == 'price') {
                 self::deleteCachePriceGroup($objSearch->id, $id_criterion_group);
             } else {
                 self::deleteCacheCriterionGroup($objSearch->id, $id_criterion_group);
             }
         }
     }
     if ($criterions_group_type == 'attribute') {
         $criterions_group = AdvancedSearchClass::getAttributeGroups($id_criterion_group_linked, false);
     } elseif ($criterions_group_type == 'feature') {
         $criterions_group = AdvancedSearchClass::getFeature($id_criterion_group_linked, false);
     } elseif ($criterions_group_type == 'category') {
         $criterions_group = array('name' => Module::getInstanceByName('pm_advancedsearch4')->translateMultiple('categories', $id_criterion_group_linked));
     } else {
         $criterions_group = array('name' => Module::getInstanceByName('pm_advancedsearch4')->translateMultiple($criterions_group_type));
     }
     if (!isset($criterions_group['name'][Configuration::get('PS_LANG_DEFAULT')]) || !trim($criterions_group['name'][Configuration::get('PS_LANG_DEFAULT')])) {
         return;
     }
     $objAdvancedSearchCriterionGroupClass = new AdvancedSearchCriterionGroupClass($id_criterion_group, $objSearch->id);
     if (!$update) {
         $objAdvancedSearchCriterionGroupClass->name = $criterions_group['name'];
     }
     $objAdvancedSearchCriterionGroupClass->visible = (int) $visible;
     if (!$visible) {
         $objAdvancedSearchCriterionGroupClass->position = 100;
     }
     $objAdvancedSearchCriterionGroupClass->criterion_group_type = $criterions_group_type;
     $objAdvancedSearchCriterionGroupClass->id_criterion_group_linked = $id_criterion_group_linked;
     if ($criterions_group_type == 'on_sale' || $criterions_group_type == 'stock' || $criterions_group_type == 'available_for_order' || $criterions_group_type == 'online_only' || $criterions_group_type == 'pack') {
         $objAdvancedSearchCriterionGroupClass->is_multicriteria = true;
         $objAdvancedSearchCriterionGroupClass->display_type = 4;
     }
     if ($objAdvancedSearchCriterionGroupClass->save()) {
         if ($criterions_group_type != 'price') {
             if ($criterions_group_type == 'attribute') {
                 $criterions = AdvancedSearchClass::getAttributes($criterions_group['id_attribute_group'], false, $id_criterion_linked);
             } elseif ($criterions_group_type == 'feature') {
                 $criterions = AdvancedSearchClass::getFeatureValuesFromValue($criterions_group['id_feature'], $cookie->id_lang, $criterion_value);
             } elseif ($criterions_group_type == 'manufacturer') {
                 $criterions = AdvancedSearchClass::getManufacturers(false, $id_criterion_linked);
             } elseif ($criterions_group_type == 'supplier') {
                 $criterions = AdvancedSearchClass::getSuppliers(false, $id_criterion_linked);
             } elseif ($criterions_group_type == 'category') {
                 $criterions = AdvancedSearchClass::getCategoriesP(false, $id_criterion_linked, $id_criterion_group_linked, $objSearch->id);
             } elseif ($criterions_group_type == 'on_sale' || $criterions_group_type == 'stock' || $criterions_group_type == 'available_for_order' || $criterions_group_type == 'online_only' || $criterions_group_type == 'pack') {
                 $criterions = self::getBooleanTrueCriteria();
             } elseif ($criterions_group_type == 'weight' || $criterions_group_type == 'width' || $criterions_group_type == 'height' || $criterions_group_type == 'depth') {
                 $criterions = self::getProductsFieldValues($criterions_group_type, $criterion_value);
             } elseif ($criterions_group_type == 'condition') {
                 $criterions = self::getConditionCriteria($criterion_value);
             }
             $sql_insert_multiple = array();
             $sql_insert_multiple_header = 'INSERT IGNORE INTO `' . _DB_PREFIX_ . 'pm_advancedsearch_cache_product_criterion_' . (int) $objSearch->id . '` (`id_cache_product`, `id_criterion`) VALUES ';
             $position = -1;
             $current_criterion_keys = array_keys($criterions);
             while (sizeof($criterions)) {
                 $position++;
                 $current_criterion = array_shift($current_criterion_keys);
                 $row = $criterions[$current_criterion];
                 unset($criterions[$current_criterion]);
                 self::$current_indexation++;
                 if ($criterions_group_type == 'category' && self::$current_indexation == self::$limit_indexation) {
                     self::$start_indexation += self::$limit_indexation;
                     $criterions = AdvancedSearchClass::getCategoriesP(false, $id_criterion_linked, $id_criterion_group_linked, $objSearch->id);
                     self::$current_indexation = 0;
                     $current_criterion_keys = array_keys($criterions);
                     $current_criterion = array_shift($current_criterion_keys);
                 }
                 if ((!isset($row['single_value']) || !$row['single_value']) && (!isset($row['name'][Configuration::get('PS_LANG_DEFAULT')]) || !strlen(trim($row['name'][Configuration::get('PS_LANG_DEFAULT')])))) {
                     continue;
                 }
                 if ($criterions_group_type == 'attribute') {
                     $current_id_criterion_linked = $row['id_attribute'];
                 } elseif ($criterions_group_type == 'feature') {
                     $current_id_criterion_linked = $row['id_feature_value'];
                 } elseif ($criterions_group_type == 'manufacturer') {
                     $current_id_criterion_linked = $row['id_manufacturer'];
                 } elseif ($criterions_group_type == 'supplier') {
                     $current_id_criterion_linked = $row['id_supplier'];
                 } elseif ($criterions_group_type == 'category') {
                     $current_id_criterion_linked = $row['id_category'];
                 } elseif ($criterions_group_type == 'on_sale' || $criterions_group_type == 'stock' || $criterions_group_type == 'available_for_order' || $criterions_group_type == 'online_only' || $criterions_group_type == 'pack') {
                     $current_id_criterion_linked = $row['value'];
                 } elseif ($criterions_group_type == 'weight' || $criterions_group_type == 'width' || $criterions_group_type == 'height' || $criterions_group_type == 'depth') {
                     $current_id_criterion_linked = $row['single_value'];
                 } elseif ($criterions_group_type == 'condition') {
                     $current_id_criterion_linked = 0;
                     $criterion_value = $row['name'][$cookie->id_lang];
                 }
                 if ($criterions_group_type == 'feature') {
                     if (isset($row['custom']) && $row['custom']) {
                         $criterion_value = $row['name'][Configuration::get('PS_LANG_DEFAULT')];
                     } else {
                         $criterion_value = null;
                     }
                 }
                 $id_criterion = false;
                 if ($update) {
                     if ($id_criterion_linked) {
                         $id_criterion = AdvancedSearchCriterionClass::getIdCriterionByTypeAndIdLinked($objSearch->id, $criterions_group_type, $id_criterion_group_linked, $id_criterion_linked);
                     } elseif ($criterion_value && ($criterions_group_type == 'weight' || $criterions_group_type == 'width' || $criterions_group_type == 'height' || $criterions_group_type == 'depth')) {
                         $id_criterion = AdvancedSearchCriterionClass::getIdCriterionByTypeAndSingleValue($objSearch->id, $criterions_group_type, $id_criterion_group_linked, $criterion_value);
                     } elseif ($criterion_value) {
                         $id_criterion = AdvancedSearchCriterionClass::getIdCriterionByTypeAndValue($objSearch->id, $cookie->id_lang, $criterions_group_type, $id_criterion_group_linked, $criterion_value);
                         if (!$id_criterion && $cookie->id_lang != Configuration::get('PS_LANG_DEFAULT') && $criterions_group_type == 'feature' && isset($row['custom']) && $row['custom'] && isset($row['name'][$cookie->id_lang])) {
                             $criterion_value = $row['name'][$cookie->id_lang];
                             $id_criterion = AdvancedSearchCriterionClass::getIdCriterionByTypeAndValue($objSearch->id, $cookie->id_lang, $criterions_group_type, $id_criterion_group_linked, $criterion_value);
                         }
                     } elseif ($current_id_criterion_linked && ($criterions_group_type == 'weight' || $criterions_group_type == 'width' || $criterions_group_type == 'height' || $criterions_group_type == 'depth')) {
                         $id_criterion = AdvancedSearchCriterionClass::getIdCriterionByTypeAndSingleValue($objSearch->id, $criterions_group_type, $id_criterion_group_linked, $current_id_criterion_linked);
                     } elseif ($current_id_criterion_linked) {
                         $id_criterion = AdvancedSearchCriterionClass::getIdCriterionByTypeAndIdLinked($objSearch->id, $criterions_group_type, $id_criterion_group_linked, $current_id_criterion_linked);
                     }
                 }
                 $objAdvancedSearchCriterionClassOld = false;
                 $objAdvancedSearchCriterionClass = new AdvancedSearchCriterionClass($id_criterion, $objSearch->id);
                 if (Validate::isLoadedObject($objAdvancedSearchCriterionClass)) {
                     $objAdvancedSearchCriterionClassOld = $objAdvancedSearchCriterionClass;
                 }
                 if ($criterions_group_type == 'attribute' || $criterions_group_type == 'feature' || $criterions_group_type == 'manufacturer' || $criterions_group_type == 'supplier' || $criterions_group_type == 'category' || $criterions_group_type == 'on_sale' || $criterions_group_type == 'stock' || $criterions_group_type == 'available_for_order' || $criterions_group_type == 'online_only' || $criterions_group_type == 'condition' || $criterions_group_type == 'pack') {
                     $objAdvancedSearchCriterionClass->value = $row['name'];
                 }
                 if (isset($row['single_value']) && $row['single_value']) {
                     $objAdvancedSearchCriterionClass->single_value = $row['single_value'];
                 }
                 if (!isset($objAdvancedSearchCriterionClass->value) && isset($objAdvancedSearchCriterionClass->single_value)) {
                     foreach (Language::getLanguages(false) as $lang) {
                         $objAdvancedSearchCriterionClass->value[$lang['id_lang']] = ' ';
                     }
                 }
                 if ($criterions_group_type == 'attribute' && $row['color']) {
                     $objAdvancedSearchCriterionClass->color = $row['color'];
                 }
                 $objAdvancedSearchCriterionClass->id_criterion_group = $objAdvancedSearchCriterionGroupClass->id;
                 $objAdvancedSearchCriterionClass->id_criterion_linked = $current_id_criterion_linked;
                 if ($criterions_group_type == 'category') {
                     $objAdvancedSearchCriterionClass->level_depth = $row['level_depth'];
                     $objAdvancedSearchCriterionClass->id_parent = $row['id_parent'];
                 }
                 if (!$update) {
                     $objAdvancedSearchCriterionClass->position = $position;
                 }
                 if (!$id_product) {
                     if ($criterions_group_type == 'attribute') {
                         $productsIdCache = AdvancedSearchClass::getProductsIdFromAttribute($objSearch->id, $row['id_attribute']);
                     } elseif ($criterions_group_type == 'feature') {
                         $productsIdCache = AdvancedSearchClass::getProductsIdFromFeatureValue($objSearch->id, $criterions_group['id_feature'], $row['name'][Configuration::get('PS_LANG_DEFAULT')], Configuration::get('PS_LANG_DEFAULT'));
                     } elseif ($criterions_group_type == 'manufacturer') {
                         $productsIdCache = AdvancedSearchClass::getProductsIdFromManufacturer($objSearch->id, $row['id_manufacturer']);
                     } elseif ($criterions_group_type == 'supplier') {
                         $productsIdCache = AdvancedSearchClass::getProductsIdFromSupplier($objSearch->id, $row['id_supplier']);
                     } elseif ($criterions_group_type == 'category') {
                         $productsIdCache = AdvancedSearchClass::getProductsIdFromCategory($objSearch->id, $row['id_category'], $objSearch->recursing_indexing);
                     } elseif ($criterions_group_type == 'on_sale' || $criterions_group_type == 'stock' || $criterions_group_type == 'available_for_order' || $criterions_group_type == 'online_only' || $criterions_group_type == 'condition' || $criterions_group_type == 'pack') {
                         $productsIdCache = AdvancedSearchClass::getProductsIdFromProductField($objSearch->id, $row['value'], $criterions_group_type);
                     } elseif ($criterions_group_type == 'weight' || $criterions_group_type == 'width' || $criterions_group_type == 'height' || $criterions_group_type == 'depth') {
                         $productsIdCache = AdvancedSearchClass::getProductsIdFromProductField($objSearch->id, $row['single_value'], $criterions_group_type);
                     }
                 } else {
                     $productsIdCache = array(array('id_cache_product' => self::getIdCacheProductFromIdProduct($objSearch->id, $id_product)));
                 }
                 if ($objAdvancedSearchCriterionClassOld !== false && sha1(serialize($objAdvancedSearchCriterionClass)) == sha1(serialize($objAdvancedSearchCriterionClassOld)) || $objAdvancedSearchCriterionClass->save()) {
                     foreach ($productsIdCache as $row) {
                         $sql_insert_multiple[] = '(' . (int) $row['id_cache_product'] . ', ' . (int) $objAdvancedSearchCriterionClass->id . ')';
                         self::sqlBulkInsert($sql_insert_multiple_header, $sql_insert_multiple, 200);
                     }
                     self::sqlBulkInsert($sql_insert_multiple_header, $sql_insert_multiple, 1);
                 }
             }
             unset($criterions, $productsIdCache);
             self::sqlBulkInsert($sql_insert_multiple_header, $sql_insert_multiple, 1);
         } elseif ($criterions_group_type == 'price') {
             AdvancedSearchClass::setProductsPrices($objSearch->id, $objAdvancedSearchCriterionGroupClass->id, $id_product);
             AdvancedSearchClass::setProductsSpecificPrices($objSearch->id, $objAdvancedSearchCriterionGroupClass->id, $id_product);
         }
     }
     self::$start_indexation = 0;
     self::$limit_indexation = 1000;
     self::$current_indexation = 0;
     return $objAdvancedSearchCriterionGroupClass->id;
 }