本文整理匯總了PHP中ProductSupplier::getIdByProductAndSupplier方法的典型用法代碼示例。如果您正苦於以下問題:PHP ProductSupplier::getIdByProductAndSupplier方法的具體用法?PHP ProductSupplier::getIdByProductAndSupplier怎麽用?PHP ProductSupplier::getIdByProductAndSupplier使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ProductSupplier
的用法示例。
在下文中一共展示了ProductSupplier::getIdByProductAndSupplier方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: productImportOne
//.........這裏部分代碼省略.........
$product_download->date_expiration = $info['date_expiration'];
$product_download->nb_days_accessible = (int) $info['nb_days_accessible'];
$product_download->display_filename = basename($info['file_url']);
$product_download->add();
}
}
}
$shops = array();
$product_shop = explode($this->multiple_value_separator, $product->shop);
foreach ($product_shop as $shop) {
if (empty($shop)) {
continue;
}
$shop = trim($shop);
if (!empty($shop) && !is_numeric($shop)) {
$shop = Shop::getIdByName($shop);
}
if (in_array($shop, $shop_ids)) {
$shops[] = $shop;
} else {
$this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Shop is not valid'));
}
}
if (empty($shops)) {
$shops = Shop::getContextListShopID();
}
// If both failed, mysql error
if (!$res) {
$this->errors[] = sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), isset($info['name']) && !empty($info['name']) ? Tools::safeOutput($info['name']) : 'No Name', isset($info['id']) && !empty($info['id']) ? Tools::safeOutput($info['id']) : 'No ID');
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
} else {
// Product supplier
if (!$validateOnly && 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();
}
// SpecificPrice (only the basic reduction feature is supported by the import)
if (!$shop_is_feature_active) {
$info['shop'] = 1;
} elseif (!isset($info['shop']) || empty($info['shop'])) {
$info['shop'] = implode($this->multiple_value_separator, Shop::getContextListShopID());
}
// Get shops for each attributes
$info['shop'] = explode($this->multiple_value_separator, $info['shop']);
$id_shop_list = array();
foreach ($info['shop'] as $shop) {
if (!empty($shop) && !is_numeric($shop)) {
$id_shop_list[] = (int) Shop::getIdByName($shop);
} elseif (!empty($shop)) {
$id_shop_list[] = $shop;
}
}
if (isset($info['reduction_price']) && $info['reduction_price'] > 0 || isset($info['reduction_percent']) && $info['reduction_percent'] > 0) {
foreach ($id_shop_list as $id_shop) {
$specific_price = SpecificPrice::getSpecificPrice($product->id, $id_shop, 0, 0, 0, 1, 0, 0, 0, 0);
if (is_array($specific_price) && isset($specific_price['id_specific_price'])) {
示例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
//.........這裏部分代碼省略.........
}
// If no id_product or update failed
if (!$res) {
if (isset($product->date_add) && $product->date_add != '') {
$res = $product->add(false);
} else {
$res = $product->add();
}
}
}
$shops = array();
$product_shop = explode($this->multiple_value_separator, $product->shop);
foreach ($product_shop as $shop) {
$shop = trim($shop);
if (!is_numeric($shop)) {
$shop = Shop::getIdByName($shop);
}
if (in_array($shop, $shop_ids)) {
$shops[] = $shop;
} else {
$this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Shop is not valid'));
}
}
if (empty($shops)) {
$shops = Shop::getContextListShopID();
}
// If both failed, mysql error
if (!$res) {
$this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), isset($info['name']) ? Tools::safeOutput($info['name']) : 'No Name', isset($info['id']) ? Tools::safeOutput($info['id']) : 'No ID');
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
} else {
// Product supplier
if (isset($product->id_supplier) && isset($product->supplier_reference)) {
$id_product_supplier = ProductSupplier::getIdByProductAndSupplier((int) $product->id, 0, (int) $product->id_supplier);
if ($id_product_supplier) {
$product_supplier = new ProductSupplier((int) $id_product_supplier);
} else {
$product_supplier = new ProductSupplier();
}
$product_supplier->id_product = $product->id;
$product_supplier->id_product_attribute = 0;
$product_supplier->id_supplier = $product->id_supplier;
$product_supplier->product_supplier_price_te = $product->wholesale_price;
$product_supplier->product_supplier_reference = $product->supplier_reference;
$product_supplier->save();
}
// SpecificPrice (only the basic reduction feature is supported by the import)
if (isset($info['reduction_price']) && $info['reduction_price'] > 0 || isset($info['reduction_percent']) && $info['reduction_percent'] > 0) {
$specific_price = new SpecificPrice();
$specific_price->id_product = (int) $product->id;
// @todo multishop specific price import
$specific_price->id_shop = $this->context->shop->id;
$specific_price->id_currency = 0;
$specific_price->id_country = 0;
$specific_price->id_group = 0;
$specific_price->price = -1;
$specific_price->id_customer = 0;
$specific_price->from_quantity = 1;
$specific_price->reduction = isset($info['reduction_price']) && $info['reduction_price'] ? $info['reduction_price'] : $info['reduction_percent'] / 100;
$specific_price->reduction_type = isset($info['reduction_price']) && $info['reduction_price'] ? 'amount' : 'percentage';
$specific_price->from = isset($info['reduction_from']) && Validate::isDate($info['reduction_from']) ? $info['reduction_from'] : '0000-00-00 00:00:00';
$specific_price->to = isset($info['reduction_to']) && Validate::isDate($info['reduction_to']) ? $info['reduction_to'] : '0000-00-00 00:00:00';
if (!$specific_price->add()) {
$this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Discount is invalid'));
}
}
示例5: productImport
//.........這裏部分代碼省略.........
$res = $product->add();
}
}
if ($product->getType() == Product::PTYPE_VIRTUAL) {
StockAvailable::setProductOutOfStock((int) $product->id, 1);
} else {
StockAvailable::setProductOutOfStock((int) $product->id, (int) $product->out_of_stock);
}
}
$shops = array();
$product_shop = explode($this->multiple_value_separator, $product->shop);
foreach ($product_shop as $shop) {
if (empty($shop)) {
continue;
}
$shop = trim($shop);
if (!empty($shop) && !is_numeric($shop)) {
$shop = Shop::getIdByName($shop);
}
if (in_array($shop, $shop_ids)) {
$shops[] = $shop;
} else {
$this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Shop is not valid'));
}
}
if (empty($shops)) {
$shops = Shop::getContextListShopID();
}
if (!$res) {
$this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), isset($info['name']) && !empty($info['name']) ? Tools::safeOutput($info['name']) : 'No Name', isset($info['id']) && !empty($info['id']) ? Tools::safeOutput($info['id']) : 'No ID');
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
} else {
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 (!Shop::isFeatureActive()) {
$info['shop'] = 1;
} elseif (!isset($info['shop']) || empty($info['shop'])) {
$info['shop'] = implode($this->multiple_value_separator, Shop::getContextListShopID());
}
$info['shop'] = explode($this->multiple_value_separator, $info['shop']);
$id_shop_list = array();
foreach ($info['shop'] as $shop) {
if (!empty($shop) && !is_numeric($shop)) {
$id_shop_list[] = (int) Shop::getIdByName($shop);
} elseif (!empty($shop)) {
$id_shop_list[] = $shop;
}
}
if (isset($info['reduction_price']) && $info['reduction_price'] > 0 || isset($info['reduction_percent']) && $info['reduction_percent'] > 0) {
foreach ($id_shop_list as $id_shop) {
$specific_price = SpecificPrice::getSpecificPrice($product->id, $id_shop, 0, 0, 0, 1, 0, 0, 0, 0);
if (is_array($specific_price) && isset($specific_price['id_specific_price'])) {
$specific_price = new SpecificPrice((int) $specific_price['id_specific_price']);
} else {
示例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
//.........這裏部分代碼省略.........