本文整理汇总了PHP中Combination::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Combination::add方法的具体用法?PHP Combination::add怎么用?PHP Combination::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Combination
的用法示例。
在下文中一共展示了Combination::add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: duplicateAttributes
/**
* Duplicate attributes when duplicating a product
*
* @param integer $id_product_old Old product id
* @param integer $id_product_new New product id
*/
public static function duplicateAttributes($id_product_old, $id_product_new)
{
$return = true;
$combination_images = array();
$result = Db::getInstance()->executeS('
SELECT *
FROM `' . _DB_PREFIX_ . 'product_attribute` pa
WHERE pa.`id_product` = ' . (int) $id_product_old);
foreach ($result as $row) {
$id_product_attribute_old = (int) $row['id_product_attribute'];
$result2 = Db::getInstance()->executeS('
SELECT *
FROM `' . _DB_PREFIX_ . 'product_attribute_combination`
WHERE `id_product_attribute` = ' . $id_product_attribute_old);
$row['id_product'] = $id_product_new;
unset($row['id_product_attribute']);
$combination = new Combination();
foreach ($row as $k => $v) {
$combination->{$k} = $v;
}
$return &= $combination->add();
$id_product_attribute_new = (int) $combination->id;
if ($result_images = Product::_getAttributeImageAssociations($id_product_attribute_old)) {
$combination_images['old'][$id_product_attribute_old] = $result_images;
$combination_images['new'][$id_product_attribute_new] = $result_images;
}
foreach ($result2 as $row2) {
$row2['id_product_attribute'] = $id_product_attribute_new;
$return &= Db::getInstance()->insert('product_attribute_combination', $row2);
}
}
return !$return ? false : $combination_images;
}
示例2: addAttribute
/**
* Add a product attribute
* @since 1.5.0.1
*
* @param float $price Additional price
* @param float $weight Additional weight
* @param float $ecotax Additional ecotax
* @param int $id_images Image ids
* @param string $reference Reference
* @param string $location Location
* @param string $ean13 Ean-13 barcode
* @param bool $default Is default attribute for product
* @param int $minimal_quantity Minimal quantity to add to cart
* @return mixed $id_product_attribute or false
*/
public function addAttribute($price, $weight, $unit_impact, $ecotax, $id_images, $reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity = 1, array $id_shop_list = array(), $available_date = null)
{
if (!$this->id) {
return;
}
$price = str_replace(',', '.', $price);
$weight = str_replace(',', '.', $weight);
$combination = new Combination();
$combination->id_product = (int) $this->id;
$combination->price = (double) $price;
$combination->ecotax = (double) $ecotax;
$combination->quantity = 0;
$combination->weight = (double) $weight;
$combination->unit_price_impact = (double) $unit_impact;
$combination->reference = pSQL($reference);
$combination->location = pSQL($location);
$combination->ean13 = pSQL($ean13);
$combination->upc = pSQL($upc);
$combination->default_on = (int) $default;
$combination->minimal_quantity = (int) $minimal_quantity;
$combination->available_date = $available_date;
if (count($id_shop_list)) {
$combination->id_shop_list = array_unique($id_shop_list);
}
$combination->add();
if (!$combination->id) {
return false;
}
$total_quantity = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT SUM(quantity) as quantity
FROM ' . _DB_PREFIX_ . 'stock_available
WHERE id_product = ' . (int) $this->id . '
AND id_product_attribute <> 0 ');
if (!$total_quantity) {
Db::getInstance()->update('stock_available', array('quantity' => 0), '`id_product` = ' . $this->id);
}
$id_default_attribute = Product::updateDefaultAttribute($this->id);
if ($id_default_attribute) {
$this->cache_default_attribute = $id_default_attribute;
if (!$combination->available_date) {
$this->setAvailableDate();
}
}
if (!empty($id_images)) {
$combination->setImages($id_images);
}
Tools::clearColorListCache($this->id);
if (Configuration::get('PS_DEFAULT_WAREHOUSE_NEW_PRODUCT') != 0 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
$warehouse_location_entity = new WarehouseProductLocation();
$warehouse_location_entity->id_product = $this->id;
$warehouse_location_entity->id_product_attribute = (int) $combination->id;
$warehouse_location_entity->id_warehouse = Configuration::get('PS_DEFAULT_WAREHOUSE_NEW_PRODUCT');
$warehouse_location_entity->location = pSQL('');
$warehouse_location_entity->save();
}
return (int) $combination->id;
}
示例3: addAttribute
/**
* Add a product attribute
* @since 1.5.0.1
*
* @param float $price Additional price
* @param float $weight Additional weight
* @param float $ecotax Additional ecotax
* @param integer $id_images Image ids
* @param string $reference Reference
* @param string $location Location
* @param string $ean13 Ean-13 barcode
* @param boolean $default Is default attribute for product
* @param integer $minimal_quantity Minimal quantity to add to cart
* @return mixed $id_product_attribute or false
*/
public function addAttribute($price, $weight, $unit_impact, $ecotax, $id_images, $reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity = 1, array $id_shop_list = array(), $available_date = null)
{
if (!$this->id) {
return;
}
$price = str_replace(',', '.', $price);
$weight = str_replace(',', '.', $weight);
$combination = new Combination();
$combination->id_product = (int) $this->id;
$combination->price = (double) $price;
$combination->ecotax = (double) $ecotax;
$combination->quantity = 0;
$combination->weight = (double) $weight;
$combination->unit_price_impact = (double) $unit_impact;
$combination->reference = pSQL($reference);
$combination->location = pSQL($location);
$combination->ean13 = pSQL($ean13);
$combination->upc = pSQL($upc);
$combination->default_on = (int) $default;
$combination->minimal_quantity = (int) $minimal_quantity;
$combination->available_date = $available_date;
if (count($id_shop_list)) {
$combination->id_shop_list = array_unique($id_shop_list);
}
$combination->add();
if (!$combination->id) {
return false;
}
$id_default_attribute = Product::updateDefaultAttribute($this->id);
if ($id_default_attribute) {
$this->cache_default_attribute = $id_default_attribute;
}
if (!empty($id_images)) {
$combination->setImages($id_images);
}
Tools::clearColorListCache($this->id);
return (int) $combination->id;
}
示例4: addAttribute
/**
* Add a product attribute
* @since 1.5.0.1
*
* @param float $price Additional price
* @param float $weight Additional weight
* @param float $ecotax Additional ecotax
* @param integer $id_images Image ids
* @param string $reference Reference
* @param string $location Location
* @param string $ean13 Ean-13 barcode
* @param boolean $default Is default attribute for product
* @param integer $minimal_quantity Minimal quantity to add to cart
* @return mixed $id_product_attribute or false
*/
public function addAttribute($price, $weight, $unit_impact, $ecotax, $id_images, $reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity = 1, array $id_shop_list = array())
{
if (!$this->id) {
return;
}
$price = str_replace(',', '.', $price);
$weight = str_replace(',', '.', $weight);
$combination = new Combination();
$combination->id_product = (int) $this->id;
$combination->price = (double) $price;
$combination->ecotax = (double) $ecotax;
$combination->quantity = 0;
$combination->weight = (double) $weight;
$combination->unit_price_impact = (double) $unit_impact;
$combination->reference = pSQL($reference);
$combination->location = pSQL($location);
$combination->ean13 = pSQL($ean13);
$combination->upc = pSQL($upc);
$combination->default_on = (int) $default;
$combination->minimal_quantity = (int) $minimal_quantity;
// if we add a combination for this shop and this product does not use the combination feature in other shop,
// we clone the default combination in every shop linked to this product
if ($default && !$this->hasAttributesInOtherShops()) {
$id_shop_list_array = Product::getShopsByProduct($this->id);
foreach ($id_shop_list_array as $array_shop) {
$id_shop_list[] = $array_shop['id_shop'];
}
$id_shop_list = array_unique($id_shop_list);
}
if (count($id_shop_list)) {
$combination->id_shop_list = array_unique($id_shop_list);
}
$combination->add();
if (!$combination->id) {
return false;
}
Product::updateDefaultAttribute($this->id);
if (!empty($id_images)) {
$combination->setImages($id_images);
}
return (int) $combination->id;
}
示例5: importProductsAttributes
protected function importProductsAttributes()
{
$this->truncateTables(array('product_attribute', 'product_attribute_combination', 'product_attribute_shop', 'product_attribute_image'));
$handle = $this->openCsvFile('product_attributes.csv');
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) {
$res = false;
$fields = $this->filterFields('Combination', $this->product_attribute_fields, $line);
if (!isset($fields['id'])) {
$attribute = new Combination($line[0]);
$attribute->id = $line[0];
} else {
$attribute = new Combination($fields['id']);
}
foreach ($fields as $key => $field) {
$attribute->{$key} = $field;
}
// add attribute values in ps_product_attribute_combination
if ($line[16]) {
$values = explode(',', $line[16]);
$attribute->setAttributes($values);
}
// add attribute images to ps_product_attribute_image
if ($line[17]) {
$images = explode(',', $line[17]);
$attribute->setImages($images);
}
$attribute->force_id = true;
if (!$res) {
$res = $attribute->add();
}
}
$this->closeCsvFile($handle);
return true;
}