本文整理汇总了PHP中Feature::cleanPositions方法的典型用法代码示例。如果您正苦于以下问题:PHP Feature::cleanPositions方法的具体用法?PHP Feature::cleanPositions怎么用?PHP Feature::cleanPositions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Feature
的用法示例。
在下文中一共展示了Feature::cleanPositions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: productImport
//.........这里部分代码省略.........
if (!is_array($product->tags)) {
$product->tags = AdminImportController::createMultiLangField($product->tags);
foreach ($product->tags as $key => $tags) {
$is_tag_added = Tag::addTags($key, $product->id, $tags, $this->multiple_value_separator);
if (!$is_tag_added) {
$this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Tags list is invalid'));
break;
}
}
} else {
foreach ($product->tags as $key => $tags) {
$str = '';
foreach ($tags as $one_tag) {
$str .= $one_tag . $this->multiple_value_separator;
}
$str = rtrim($str, $this->multiple_value_separator);
$is_tag_added = Tag::addTags($key, $product->id, $str, $this->multiple_value_separator);
if (!$is_tag_added) {
$this->addProductWarning(Tools::safeOutput($info['name']), (int) $product->id, 'Invalid tag(s) (' . $str . ')');
break;
}
}
}
}
//delete existing images if "delete_existing_images" is set to 1
if (isset($product->delete_existing_images)) {
if ((bool) $product->delete_existing_images) {
$product->deleteImages();
} else {
if (isset($product->image) && is_array($product->image) && count($product->image)) {
$product->deleteImages();
}
}
}
if (isset($product->image) && is_array($product->image) && count($product->image)) {
$product_has_images = (bool) Image::getImages($this->context->language->id, (int) $product->id);
foreach ($product->image as $key => $url) {
$url = trim($url);
$error = false;
if (!empty($url)) {
$url = str_replace(' ', '%20', $url);
$image = new Image();
$image->id_product = (int) $product->id;
$image->position = Image::getHighestPosition($product->id) + 1;
$image->cover = !$key && !$product_has_images ? true : false;
// file_exists doesn't work with HTTP protocol
if (@fopen($url, 'r') == false) {
$error = true;
} else {
if (($field_error = $image->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $image->add()) {
// associate image to selected shops
$image->associateTo($shops);
if (!AdminImportController::copyImg($product->id, $image->id, $url)) {
$image->delete();
$this->warnings[] = sprintf(Tools::displayError('Error copying image: %s'), $url);
}
} else {
$error = true;
}
}
} else {
$error = true;
}
if ($error) {
$this->warnings[] = sprintf(Tools::displayError('Product n°%1$d: the picture cannot be saved: %2$s'), $image->id_product, $url);
}
}
}
if (isset($product->id_category)) {
$product->updateCategories(array_map('intval', $product->id_category));
}
// Features import
$features = get_object_vars($product);
if (isset($features['features']) && !empty($features['features'])) {
foreach (explode($this->multiple_value_separator, $features['features']) as $single_feature) {
$tab_feature = explode(':', $single_feature);
$feature_name = trim($tab_feature[0]);
$feature_value = trim($tab_feature[1]);
$position = isset($tab_feature[2]) ? $tab_feature[2] : false;
if (!empty($feature_name) && !empty($feature_value)) {
$id_feature = Feature::addFeatureImport($feature_name, $position);
$id_feature_value = FeatureValue::addFeatureValueImport($id_feature, $feature_value);
Product::addFeatureProductImport($product->id, $id_feature, $id_feature_value);
}
}
}
// clean feature positions to avoid conflict
Feature::cleanPositions();
}
// stock available
if (Shop::isFeatureActive()) {
foreach ($shops as $shop) {
StockAvailable::setQuantity((int) $product->id, 0, $product->quantity, (int) $shop);
}
} else {
StockAvailable::setQuantity((int) $product->id, 0, $product->quantity, $this->context->shop->id);
}
}
$this->closeCsvFile($handle);
}
示例2: productImportOne
//.........这里部分代码省略.........
}
}
if (!$validateOnly && isset($product->id_category) && is_array($product->id_category)) {
$product->updateCategories(array_map('intval', $product->id_category));
}
$product->checkDefaultAttributes();
if (!$validateOnly && !$product->cache_default_attribute) {
Product::updateDefaultAttribute($product->id);
}
// Features import
$features = get_object_vars($product);
if (!$validateOnly && isset($features['features']) && !empty($features['features'])) {
foreach (explode($this->multiple_value_separator, $features['features']) as $single_feature) {
if (empty($single_feature)) {
continue;
}
$tab_feature = explode(':', $single_feature);
$feature_name = isset($tab_feature[0]) ? trim($tab_feature[0]) : '';
$feature_value = isset($tab_feature[1]) ? trim($tab_feature[1]) : '';
$position = isset($tab_feature[2]) ? (int) $tab_feature[2] - 1 : false;
$custom = isset($tab_feature[3]) ? (int) $tab_feature[3] : false;
if (!empty($feature_name) && !empty($feature_value)) {
$id_feature = (int) Feature::addFeatureImport($feature_name, $position);
$id_product = null;
if ($force_ids || $match_ref) {
$id_product = (int) $product->id;
}
$id_feature_value = (int) FeatureValue::addFeatureValueImport($id_feature, $feature_value, $id_product, $id_lang, $custom);
Product::addFeatureProductImport($product->id, $id_feature, $id_feature_value);
}
}
}
// clean feature positions to avoid conflict
Feature::cleanPositions();
// set advanced stock managment
if (!$validateOnly && isset($product->advanced_stock_management)) {
if ($product->advanced_stock_management != 1 && $product->advanced_stock_management != 0) {
$this->warnings[] = sprintf($this->trans('Advanced stock management has incorrect value. Not set for product %1$s ', array(), 'Admin.Parameters.Notification'), $product->name[$default_language_id]);
} elseif (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management == 1) {
$this->warnings[] = sprintf($this->trans('Advanced stock management is not enabled, cannot enable on product %1$s ', array(), 'Admin.Parameters.Notification'), $product->name[$default_language_id]);
} elseif ($update_advanced_stock_management_value) {
$product->setAdvancedStockManagement($product->advanced_stock_management);
}
// automaticly disable depends on stock, if a_s_m set to disabled
if (StockAvailable::dependsOnStock($product->id) == 1 && $product->advanced_stock_management == 0) {
StockAvailable::setProductDependsOnStock($product->id, 0);
}
}
// Check if warehouse exists
if (isset($product->warehouse) && $product->warehouse) {
if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
$this->warnings[] = sprintf($this->trans('Advanced stock management is not enabled, warehouse not set on product %1$s ', array(), 'Admin.Parameters.Notification'), $product->name[$default_language_id]);
} elseif (!$validateOnly) {
if (Warehouse::exists($product->warehouse)) {
// Get already associated warehouses
$associated_warehouses_collection = WarehouseProductLocation::getCollection($product->id);
// Delete any entry in warehouse for this product
foreach ($associated_warehouses_collection as $awc) {
$awc->delete();
}
$warehouse_location_entity = new WarehouseProductLocation();
$warehouse_location_entity->id_product = $product->id;
$warehouse_location_entity->id_product_attribute = 0;
$warehouse_location_entity->id_warehouse = $product->warehouse;
if (WarehouseProductLocation::getProductLocation($product->id, 0, $product->warehouse) !== false) {
$warehouse_location_entity->update();
示例3: productImport
//.........这里部分代码省略.........
$this->warnings[] = sprintf(Tools::displayError('Product #%1$d: the picture (%2$s) cannot be saved.'), $image->id_product, $url);
}
}
}
if (isset($product->id_category) && is_array($product->id_category)) {
$product->updateCategories(array_map('intval', $product->id_category));
}
$product->checkDefaultAttributes();
if (!$product->cache_default_attribute) {
Product::updateDefaultAttribute($product->id);
}
$features = get_object_vars($product);
if (isset($features['features']) && !empty($features['features'])) {
foreach (explode($this->multiple_value_separator, $features['features']) as $single_feature) {
if (empty($single_feature)) {
continue;
}
$tab_feature = explode(':', $single_feature);
$feature_name = isset($tab_feature[0]) ? trim($tab_feature[0]) : '';
$feature_value = isset($tab_feature[1]) ? trim($tab_feature[1]) : '';
$position = isset($tab_feature[2]) ? (int) $tab_feature[2] - 1 : false;
$custom = isset($tab_feature[3]) ? (int) $tab_feature[3] : false;
if (!empty($feature_name) && !empty($feature_value)) {
$id_feature = (int) Feature::addFeatureImport($feature_name, $position);
$id_product = null;
if (Tools::getValue('forceIDs') || Tools::getValue('match_ref')) {
$id_product = (int) $product->id;
}
$id_feature_value = (int) FeatureValue::addFeatureValueImport($id_feature, $feature_value, $id_product, $id_lang, $custom);
Product::addFeatureProductImport($product->id, $id_feature, $id_feature_value);
}
}
}
Feature::cleanPositions();
if (isset($product->advanced_stock_management)) {
if ($product->advanced_stock_management != 1 && $product->advanced_stock_management != 0) {
$this->warnings[] = sprintf(Tools::displayError('Advanced stock management has incorrect value. Not set for product %1$s '), $product->name[$default_language_id]);
} elseif (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management == 1) {
$this->warnings[] = sprintf(Tools::displayError('Advanced stock management is not enabled, cannot enable on product %1$s '), $product->name[$default_language_id]);
} else {
$product->setAdvancedStockManagement($product->advanced_stock_management);
}
if (StockAvailable::dependsOnStock($product->id) == 1 && $product->advanced_stock_management == 0) {
StockAvailable::setProductDependsOnStock($product->id, 0);
}
}
if (isset($product->warehouse) && $product->warehouse) {
if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
$this->warnings[] = sprintf(Tools::displayError('Advanced stock management is not enabled, warehouse not set on product %1$s '), $product->name[$default_language_id]);
} else {
if (Warehouse::exists($product->warehouse)) {
$associated_warehouses_collection = WarehouseProductLocation::getCollection($product->id);
foreach ($associated_warehouses_collection as $awc) {
$awc->delete();
}
$warehouse_location_entity = new WarehouseProductLocation();
$warehouse_location_entity->id_product = $product->id;
$warehouse_location_entity->id_product_attribute = 0;
$warehouse_location_entity->id_warehouse = $product->warehouse;
if (WarehouseProductLocation::getProductLocation($product->id, 0, $product->warehouse) !== false) {
$warehouse_location_entity->update();
} else {
$warehouse_location_entity->save();
}
StockAvailable::synchronize($product->id);
} else {