本文整理汇总了PHP中ProductSupplier::save方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductSupplier::save方法的具体用法?PHP ProductSupplier::save怎么用?PHP ProductSupplier::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductSupplier
的用法示例。
在下文中一共展示了ProductSupplier::save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: productImportOne
protected function productImportOne($info, $default_language_id, $id_lang, $force_ids, $regenerate, $shop_is_feature_active, $shop_ids, $match_ref, &$accessories, $validateOnly = false)
{
if ($force_ids && isset($info['id']) && (int) $info['id']) {
$product = new Product((int) $info['id']);
} elseif ($match_ref && array_key_exists('reference', $info)) {
$datas = Db::getInstance()->getRow('
SELECT p.`id_product`
FROM `' . _DB_PREFIX_ . 'product` p
' . Shop::addSqlAssociation('product', 'p') . '
WHERE p.`reference` = "' . pSQL($info['reference']) . '"
', false);
if (isset($datas['id_product']) && $datas['id_product']) {
$product = new Product((int) $datas['id_product']);
} else {
$product = new Product();
}
} elseif (array_key_exists('id', $info) && (int) $info['id'] && Product::existsInDatabase((int) $info['id'], 'product')) {
$product = new Product((int) $info['id']);
} else {
$product = new Product();
}
$update_advanced_stock_management_value = false;
if (isset($product->id) && $product->id && Product::existsInDatabase((int) $product->id, 'product')) {
$product->loadStockData();
$update_advanced_stock_management_value = true;
$category_data = Product::getProductCategories((int) $product->id);
if (is_array($category_data)) {
foreach ($category_data as $tmp) {
if (!isset($product->category) || !$product->category || is_array($product->category)) {
$product->category[] = $tmp;
}
}
}
}
AdminImportController::setEntityDefaultValues($product);
AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $product);
if (!$shop_is_feature_active) {
$product->shop = (int) Configuration::get('PS_SHOP_DEFAULT');
} elseif (!isset($product->shop) || empty($product->shop)) {
$product->shop = implode($this->multiple_value_separator, Shop::getContextListShopID());
}
if (!$shop_is_feature_active) {
$product->id_shop_default = (int) Configuration::get('PS_SHOP_DEFAULT');
} else {
$product->id_shop_default = (int) Context::getContext()->shop->id;
}
// link product to shops
$product->id_shop_list = array();
foreach (explode($this->multiple_value_separator, $product->shop) as $shop) {
if (!empty($shop) && !is_numeric($shop)) {
$product->id_shop_list[] = Shop::getIdByName($shop);
} elseif (!empty($shop)) {
$product->id_shop_list[] = $shop;
}
}
if ((int) $product->id_tax_rules_group != 0) {
if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group))) {
$address = $this->context->shop->getAddress();
$tax_manager = TaxManagerFactory::getManager($address, $product->id_tax_rules_group);
$product_tax_calculator = $tax_manager->getTaxCalculator();
$product->tax_rate = $product_tax_calculator->getTotalRate();
} else {
$this->addProductWarning('id_tax_rules_group', $product->id_tax_rules_group, $this->trans('Unknown tax rule group ID. You need to create a group with this ID first.', array(), 'Admin.Parameters.Notification'));
}
}
if (isset($product->manufacturer) && is_numeric($product->manufacturer) && Manufacturer::manufacturerExists((int) $product->manufacturer)) {
$product->id_manufacturer = (int) $product->manufacturer;
} elseif (isset($product->manufacturer) && is_string($product->manufacturer) && !empty($product->manufacturer)) {
if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) {
$product->id_manufacturer = (int) $manufacturer;
} else {
$manufacturer = new Manufacturer();
$manufacturer->name = $product->manufacturer;
$manufacturer->active = true;
if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $manufacturer->add()) {
$product->id_manufacturer = (int) $manufacturer->id;
$manufacturer->associateTo($product->id_shop_list);
} else {
if (!$validateOnly) {
$this->errors[] = sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), $manufacturer->name, isset($manufacturer->id) && !empty($manufacturer->id) ? $manufacturer->id : 'null');
}
if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) {
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
}
}
}
}
if (isset($product->supplier) && is_numeric($product->supplier) && Supplier::supplierExists((int) $product->supplier)) {
$product->id_supplier = (int) $product->supplier;
} elseif (isset($product->supplier) && is_string($product->supplier) && !empty($product->supplier)) {
if ($supplier = Supplier::getIdByName($product->supplier)) {
$product->id_supplier = (int) $supplier;
} else {
$supplier = new Supplier();
$supplier->name = $product->supplier;
$supplier->active = true;
if (($field_error = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $supplier->add()) {
$product->id_supplier = (int) $supplier->id;
$supplier->associateTo($product->id_shop_list);
} else {
//.........这里部分代码省略.........
示例2: addSupplierReference
/**
* Sets Supplier Reference
*
* @param int $id_supplier
* @param int $id_product_attribute
* @param string $supplier_reference
* @param float $price
* @param int $id_currency
*/
public function addSupplierReference($id_supplier, $id_product_attribute, $supplier_reference = null, $price = null, $id_currency = null)
{
//in some case we need to add price without supplier reference
if ($supplier_reference === null) {
$supplier_reference = '';
}
//Try to set the default supplier reference
if ($id_supplier > 0) {
$id_product_supplier = (int) ProductSupplier::getIdByProductAndSupplier($this->id, $id_product_attribute, $id_supplier);
if (!$id_product_supplier) {
//create new record
$product_supplier_entity = new ProductSupplier();
$product_supplier_entity->id_product = (int) $this->id;
$product_supplier_entity->id_product_attribute = (int) $id_product_attribute;
$product_supplier_entity->id_supplier = (int) $id_supplier;
$product_supplier_entity->product_supplier_reference = pSQL($supplier_reference);
$product_supplier_entity->product_supplier_price_te = (int) $price;
$product_supplier_entity->id_currency = (int) $id_currency;
$product_supplier_entity->save();
} else {
$product_supplier = new ProductSupplier((int) $id_product_supplier);
$product_supplier->product_supplier_reference = pSQL($supplier_reference);
$product_supplier->update();
}
}
}
示例3: addSupplierReference
/**
* Sets or updates Supplier Reference
*
* @param int $id_supplier
* @param int $id_product_attribute
* @param string $supplier_reference
* @param float $price
* @param int $id_currency
*/
public function addSupplierReference($id_supplier, $id_product_attribute, $supplier_reference = null, $price = null, $id_currency = null)
{
//in some case we need to add price without supplier reference
if ($supplier_reference === null) {
$supplier_reference = '';
}
//Try to set the default supplier reference
if ($id_supplier > 0 && $this->id > 0) {
$id_product_supplier = (int) ProductSupplier::getIdByProductAndSupplier($this->id, $id_product_attribute, $id_supplier);
$product_supplier = new ProductSupplier($id_product_supplier);
if (!$id_product_supplier) {
$product_supplier->id_product = (int) $this->id;
$product_supplier->id_product_attribute = (int) $id_product_attribute;
$product_supplier->id_supplier = (int) $id_supplier;
}
$product_supplier->product_supplier_reference = pSQL($supplier_reference);
$product_supplier->product_supplier_price_te = !is_null($price) ? (double) $price : (double) $product_supplier->product_supplier_price_te;
$product_supplier->id_currency = !is_null($id_currency) ? (int) $id_currency : (int) $product_supplier->id_currency;
$product_supplier->save();
}
}
示例4: productImport
public function productImport()
{
$this->receiveTab();
$handle = $this->openCsvFile();
$default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
AdminImportController::setLocale();
$shop_ids = Shop::getCompleteListOfShopsID();
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
if (Tools::getValue('convert')) {
$line = $this->utf8EncodeArray($line);
}
$info = AdminImportController::getMaskedRow($line);
if (Tools::getValue('forceIDs') && isset($info['id']) && (int) $info['id']) {
$product = new Product((int) $info['id']);
} else {
if (array_key_exists('id', $info) && (int) $info['id'] && Product::existsInDatabase((int) $info['id'], 'product')) {
$product = new Product((int) $info['id']);
} else {
$product = new Product();
}
}
if (array_key_exists('id', $info) && (int) $info['id'] && Product::existsInDatabase((int) $info['id'], 'product')) {
$product->loadStockData();
$category_data = Product::getProductCategories((int) $product->id);
foreach ($category_data as $tmp) {
$product->category[] = $tmp;
}
}
AdminImportController::setEntityDefaultValues($product);
AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $product);
if (!Shop::isFeatureActive()) {
$product->shop = 1;
} elseif (!isset($product->shop) || empty($product->shop)) {
$product->shop = implode($this->multiple_value_separator, Shop::getContextListShopID());
}
if (!Shop::isFeatureActive()) {
$product->id_shop_default = 1;
} else {
$product->id_shop_default = (int) Context::getContext()->shop->id;
}
// link product to shops
$product->id_shop_list = array();
foreach (explode($this->multiple_value_separator, $product->shop) as $shop) {
if (!is_numeric($shop)) {
$product->id_shop_list[] = Shop::getIdByName($shop);
} else {
$product->id_shop_list[] = $shop;
}
}
if ((int) $product->id_tax_rules_group != 0) {
if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group))) {
$address = $this->context->shop->getAddress();
$tax_manager = TaxManagerFactory::getManager($address, $product->id_tax_rules_group);
$product_tax_calculator = $tax_manager->getTaxCalculator();
$product->tax_rate = $product_tax_calculator->getTotalRate();
} else {
$this->addProductWarning('id_tax_rules_group', $product->id_tax_rules_group, Tools::displayError('Invalid tax rule group ID. You first need to create a group with this ID.'));
}
}
if (isset($product->manufacturer) && is_numeric($product->manufacturer) && Manufacturer::manufacturerExists((int) $product->manufacturer)) {
$product->id_manufacturer = (int) $product->manufacturer;
} else {
if (isset($product->manufacturer) && is_string($product->manufacturer) && !empty($product->manufacturer)) {
if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) {
$product->id_manufacturer = (int) $manufacturer;
} else {
$manufacturer = new Manufacturer();
$manufacturer->name = $product->manufacturer;
if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $manufacturer->add()) {
$product->id_manufacturer = (int) $manufacturer->id;
} else {
$this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $manufacturer->name, isset($manufacturer->id) ? $manufacturer->id : 'null');
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
}
}
}
}
if (isset($product->supplier) && is_numeric($product->supplier) && Supplier::supplierExists((int) $product->supplier)) {
$product->id_supplier = (int) $product->supplier;
} else {
if (isset($product->supplier) && is_string($product->supplier) && !empty($product->supplier)) {
if ($supplier = Supplier::getIdByName($product->supplier)) {
$product->id_supplier = (int) $supplier;
} else {
$supplier = new Supplier();
$supplier->name = $product->supplier;
$supplier->active = true;
if (($field_error = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $supplier->add()) {
$product->id_supplier = (int) $supplier->id;
$supplier->associateTo($product->id_shop_list);
} else {
$this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $supplier->name, isset($supplier->id) ? $supplier->id : 'null');
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
}
}
}
}
if (isset($product->price_tex) && !isset($product->price_tin)) {
$product->price = $product->price_tex;
} else {
//.........这里部分代码省略.........
示例5: productImport
public function productImport()
{
$this->receiveTab();
$handle = $this->openCsvFile();
$default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
$id_lang = Language::getIdByIso(Tools::getValue('iso_lang'));
if (!Validate::isUnsignedId($id_lang)) {
$id_lang = $default_language_id;
}
AdminImportController::setLocale();
$shop_ids = Shop::getCompleteListOfShopsID();
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
if (Tools::getValue('convert')) {
$line = $this->utf8EncodeArray($line);
}
$info = AdminImportController::getMaskedRow($line);
if (self::ignoreRow($info)) {
continue;
}
if (Tools::getValue('forceIDs') && isset($info['id']) && (int) $info['id']) {
$product = new Product((int) $info['id']);
} elseif (Tools::getValue('match_ref') && array_key_exists('reference', $info)) {
$datas = Db::getInstance()->getRow('
SELECT p.`id_product`
FROM `' . _DB_PREFIX_ . 'product` p
' . Shop::addSqlAssociation('product', 'p') . '
WHERE p.`reference` = "' . pSQL($info['reference']) . '"
');
if (isset($datas['id_product']) && $datas['id_product']) {
$product = new Product((int) $datas['id_product']);
} else {
$product = new Product();
}
} else {
if (array_key_exists('id', $info) && is_string($info['id'])) {
$prod = self::findProductByName($default_language_id, $info['id'], $info['name']);
if ($prod['id_product']) {
$info['id'] = (int) $prod['id_product'];
}
}
if (array_key_exists('id', $info) && (int) $info['id'] && Product::existsInDatabase((int) $info['id'], 'product')) {
$product = new Product((int) $info['id']);
$product->loadStockData();
$category_data = Product::getProductCategories((int) $product->id);
if (is_array($category_data)) {
foreach ($category_data as $tmp) {
if (!isset($product->category) || !$product->category || is_array($product->category)) {
$product->category[] = $tmp;
}
}
}
} else {
$product = new Product();
}
}
AdminImportController::setEntityDefaultValues($product);
AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $product);
if (!Shop::isFeatureActive()) {
$product->shop = 1;
} elseif (!isset($product->shop) || empty($product->shop)) {
$product->shop = implode($this->multiple_value_separator, Shop::getContextListShopID());
}
if (!Shop::isFeatureActive()) {
$product->id_shop_default = 1;
} else {
$product->id_shop_default = (int) Context::getContext()->shop->id;
}
$product->id_shop_list = array();
foreach (explode($this->multiple_value_separator, $product->shop) as $shop) {
if (!empty($shop) && !is_numeric($shop)) {
$product->id_shop_list[] = Shop::getIdByName($shop);
} elseif (!empty($shop)) {
$product->id_shop_list[] = $shop;
}
}
if ((int) $product->id_tax_rules_group != 0) {
if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group))) {
$address = $this->context->shop->getAddress();
$tax_manager = TaxManagerFactory::getManager($address, $product->id_tax_rules_group);
$product_tax_calculator = $tax_manager->getTaxCalculator();
$product->tax_rate = $product_tax_calculator->getTotalRate();
} else {
$this->addProductWarning('id_tax_rules_group', $product->id_tax_rules_group, Tools::displayError('Invalid tax rule group ID. You first need to create a group with this ID.'));
}
}
if (isset($product->manufacturer) && is_numeric($product->manufacturer) && Manufacturer::manufacturerExists((int) $product->manufacturer)) {
$product->id_manufacturer = (int) $product->manufacturer;
} elseif (isset($product->manufacturer) && is_string($product->manufacturer) && !empty($product->manufacturer)) {
if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) {
$product->id_manufacturer = (int) $manufacturer;
} else {
$manufacturer = new Manufacturer();
$manufacturer->name = $product->manufacturer;
if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $manufacturer->add()) {
$product->id_manufacturer = (int) $manufacturer->id;
} else {
$this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $manufacturer->name, isset($manufacturer->id) && !empty($manufacturer->id) ? $manufacturer->id : 'null');
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
}
}
//.........这里部分代码省略.........
示例6: importProducts
protected function importProducts()
{
$this->truncateTables(array('product', 'product_lang', 'product_shop', 'product_sale', 'product_supplier', 'product_tag', 'feature_product', 'category_product', 'product_carrier', 'compare_product', 'product_attachment', 'product_country_tax', 'product_download', 'product_group_reduction_cache', 'scene_products', 'warehouse_product_location', 'customization', 'customization_field', 'customization_field_lang', 'supply_order_detail', 'attribute_impact', 'pack'));
$handle = $this->openCsvFile('products.csv');
$languages = Language::getLanguages(false);
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) {
$res = false;
$product = new Product((int) $line[0]);
$product->id = (int) $line[0];
$product->active = $line[1];
foreach ($languages as $lang) {
$product->name[$lang['id_lang']] = $line['2'];
}
$categories = explode(',', $line[3]);
$product->id_category_default = $categories[0] ? $categories[0] : Configuration::get('PS_HOME_CATEGORY');
if (isset($categories) && $categories && count($categories)) {
$product->addToCategories($categories);
}
if (isset($line[4])) {
$product->price_tex = $line[4];
}
if (isset($line[5])) {
$product->price_tin = $line[5];
}
$product->id_tax_rules_group = trim($line[6]) ? $line[6] : 0;
$product->wholesale_price = trim($line[7]) ? $line[7] : 0;
$product->on_sale = trim($line[8]) ? $line[8] : 0;
if (trim($line[13])) {
$product->reference = $line[13];
}
if (trim($line[14])) {
$product->supplier_reference = trim($line[14]);
}
if (trim($line[15])) {
$product->id_supplier = (int) $line[15];
}
if (isset($product->id) && $product->id && isset($product->id_supplier) && property_exists($product, 'supplier_reference')) {
$id_product_supplier = (int) ProductSupplier::getIdByProductAndSupplier((int) $product->id, 0, (int) $product->id_supplier);
if ($id_product_supplier) {
$product_supplier = new ProductSupplier($id_product_supplier);
} else {
$product_supplier = new ProductSupplier();
}
$product_supplier->id_product = (int) $product->id;
$product_supplier->id_product_attribute = 0;
$product_supplier->id_supplier = (int) $product->id_supplier;
$product_supplier->product_supplier_price_te = $product->wholesale_price;
$product_supplier->product_supplier_reference = $product->supplier_reference;
$product_supplier->save();
}
if (trim($line[16])) {
$product->id_manufacturer = $line[16];
}
if (!Tools::isEmpty(trim($line[17]))) {
$product->ean13 = $line[17];
}
if (trim($line[18])) {
$product->upc = $line[18];
}
if (trim($line[19])) {
$product->ecotax = $line[19];
}
$product->width = $line[20];
$product->height = $line[21];
$product->depth = $line[22];
$product->weight = $line[23];
if ($line[24]) {
StockAvailable::setQuantity((int) $product->id, 0, (int) $line[24], (int) $this->context->shop->id);
}
$product->minimal_quantity = $line[25];
$product->visibility = $line[26];
$product->additional_shipping_cost = $line[27];
if (trim($line[28])) {
$product->unity = $line[28];
}
if (trim($line[29])) {
$product->unit_price = $line[29];
}
foreach ($languages as $lang) {
$product->description_short[$lang['id_lang']] = $line[30];
$product->description[$lang['id_lang']] = $line[31];
}
if ($line[32]) {
foreach ($languages as $lang) {
Tag::addTags($lang['id_lang'], $product->id, $line[32]);
}
}
foreach ($languages as $lang) {
$product->meta_title[$lang['id_lang']] = $line[33];
$product->meta_keywords[$lang['id_lang']] = $line[34];
$product->meta_description[$lang['id_lang']] = $line[35];
$product->link_rewrite[$lang['id_lang']] = $line[36];
$product->available_now[$lang['id_lang']] = $line[37];
$product->available_later[$lang['id_lang']] = $line[38];
}
$product->available_for_order = $line[39];
$product->available_date = $line[40];
$product->date_add = $line[41];
$product->show_price = $line[42];
// Features import
//.........这里部分代码省略.........