本文整理汇总了PHP中Combination::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Combination::setAttributes方法的具体用法?PHP Combination::setAttributes怎么用?PHP Combination::setAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Combination
的用法示例。
在下文中一共展示了Combination::setAttributes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processProductAttribute
public function processProductAttribute()
{
// Don't process if the combination fields have not been submitted
if (!Combination::isFeatureActive() || !Tools::getValue('attribute_combination_list')) {
return;
}
if (Validate::isLoadedObject($product = $this->object)) {
if ($this->isProductFieldUpdated('attribute_price') && (!Tools::getIsset('attribute_price') || Tools::getIsset('attribute_price') == null)) {
$this->errors[] = Tools::displayError('Attribute price required.');
}
if (!Tools::getIsset('attribute_combination_list') || Tools::isEmpty(Tools::getValue('attribute_combination_list'))) {
$this->errors[] = Tools::displayError('You must add at least one attribute.');
}
if (!count($this->errors)) {
if (!isset($_POST['attribute_wholesale_price'])) {
$_POST['attribute_wholesale_price'] = 0;
}
if (!isset($_POST['attribute_price_impact'])) {
$_POST['attribute_price_impact'] = 0;
}
if (!isset($_POST['attribute_weight_impact'])) {
$_POST['attribute_weight_impact'] = 0;
}
if (!isset($_POST['attribute_ecotax'])) {
$_POST['attribute_ecotax'] = 0;
}
if (Tools::getValue('attribute_default')) {
$product->deleteDefaultAttributes();
}
// Change existing one
if (($id_product_attribute = (int) Tools::getValue('id_product_attribute')) || ($id_product_attribute = $product->productAttributeExists(Tools::getValue('attribute_combination_list'), false, null, true, true))) {
if ($this->tabAccess['edit'] === '1') {
if ($this->isProductFieldUpdated('available_date_attribute') && !Validate::isDateFormat(Tools::getValue('available_date_attribute'))) {
$this->errors[] = Tools::displayError('Invalid date format.');
} else {
$product->updateAttribute((int) $id_product_attribute, $this->isProductFieldUpdated('attribute_wholesale_price') ? Tools::getValue('attribute_wholesale_price') : null, $this->isProductFieldUpdated('attribute_price_impact') ? Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact') : null, $this->isProductFieldUpdated('attribute_weight_impact') ? Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact') : null, $this->isProductFieldUpdated('attribute_unit_impact') ? Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact') : null, $this->isProductFieldUpdated('attribute_ecotax') ? Tools::getValue('attribute_ecotax') : null, Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_ean13'), $this->isProductFieldUpdated('attribute_default') ? Tools::getValue('attribute_default') : null, Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), $this->isProductFieldUpdated('attribute_minimal_quantity') ? Tools::getValue('attribute_minimal_quantity') : null, $this->isProductFieldUpdated('available_date_attribute') ? Tools::getValue('available_date_attribute') : null, false);
StockAvailable::setProductDependsOnStock((int) $product->id, $product->depends_on_stock, null, (int) $id_product_attribute);
StockAvailable::setProductOutOfStock((int) $product->id, $product->out_of_stock, null, (int) $id_product_attribute);
}
} else {
$this->errors[] = Tools::displayError('You do not have permission to add here.');
}
} else {
if ($this->tabAccess['add'] === '1') {
if ($product->productAttributeExists(Tools::getValue('attribute_combination_list'))) {
$this->errors[] = Tools::displayError('This combination already exists.');
} else {
$id_product_attribute = $product->addCombinationEntity(Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'), Tools::getValue('attribute_ecotax'), 0, Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), null, Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), Tools::getValue('attribute_minimal_quantity'));
StockAvailable::setProductDependsOnStock((int) $product->id, $product->depends_on_stock, null, (int) $id_product_attribute);
StockAvailable::setProductOutOfStock((int) $product->id, $product->out_of_stock, null, (int) $id_product_attribute);
}
} else {
$this->errors[] = Tools::displayError('You do not have permission to') . '<hr>' . Tools::displayError('Edit here.');
}
}
if (!count($this->errors)) {
$combination = new Combination((int) $id_product_attribute);
$combination->setAttributes(Tools::getValue('attribute_combination_list'));
$product->checkDefaultAttributes();
}
if (!count($this->errors)) {
if (!$product->cache_default_attribute) {
Product::updateDefaultAttribute($product->id);
}
}
}
}
}
示例2: addAttributeCombinaison
/**
* Add a product attributes combinaison
*
* @param integer $id_product_attribute Product attribute id
* @param array $attributes Attributes to forge combinaison
* @return array Insertion result
* @deprecated since 1.5.0.7
*/
public function addAttributeCombinaison($id_product_attribute, $attributes)
{
Tools::displayAsDeprecated();
if (!is_array($attributes)) {
die(Tools::displayError());
}
if (!count($attributes)) {
return false;
}
$combination = new Combination((int) $id_product_attribute);
return $combination->setAttributes($attributes);
}
示例3: 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;
}