本文整理汇总了PHP中Hook::updateProductAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Hook::updateProductAttribute方法的具体用法?PHP Hook::updateProductAttribute怎么用?PHP Hook::updateProductAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hook
的用法示例。
在下文中一共展示了Hook::updateProductAttribute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postProcess
//.........这里部分代码省略.........
} else {
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
} elseif (Tools::isSubmit('submitProductAttribute')) {
if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) {
if (!isset($_POST['attribute_price']) or $_POST['attribute_price'] == NULL) {
$this->_errors[] = Tools::displayError('Attribute price required.');
}
if (!isset($_POST['attribute_combinaison_list']) or !sizeof($_POST['attribute_combinaison_list'])) {
$this->_errors[] = Tools::displayError('You must add at least one attribute.');
}
if (!sizeof($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')) {
if ($this->tabAccess['edit'] === '1') {
if ($product->productAttributeExists($_POST['attribute_combinaison_list'], $id_product_attribute)) {
$this->_errors[] = Tools::displayError('This attribute already exists.');
} else {
$product->updateProductAttribute($id_product_attribute, 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'), false, Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_supplier_reference'), Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), Tools::getValue('attribute_minimal_quantity'));
if ($id_reason = (int) Tools::getValue('id_mvt_reason') and (int) Tools::getValue('attribute_mvt_quantity') > 0 and $id_reason > 0) {
$reason = new StockMvtReason((int) $id_reason);
$qty = Tools::getValue('attribute_mvt_quantity') * $reason->sign;
if (!$product->addStockMvt($qty, $id_reason, (int) $id_product_attribute, NULL, $cookie->id_employee)) {
$this->_errors[] = Tools::displayError('An error occurred while updating qty.');
}
}
Hook::updateProductAttribute((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($_POST['attribute_combinaison_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'), Tools::getValue('attribute_quantity'), Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_supplier_reference'), Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), Tools::getValue('attribute_minimal_quantity'));
}
} else {
$this->_errors[] = Tools::displayError('You do not have permission to') . '<hr>' . Tools::displayError('Edit here.');
}
}
if (!sizeof($this->_errors)) {
$product->addAttributeCombinaison($id_product_attribute, Tools::getValue('attribute_combinaison_list'));
$product->checkDefaultAttributes();
}
if (!sizeof($this->_errors)) {
if (!$product->cache_default_attribute) {
Product::updateDefaultAttribute($product->id);
}
Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=3&token=' . ($token ? $token : $this->token));
示例2: updateProductAttribute
/**
* Update a product attribute
*
* @param integer $id_product_attribute Product attribute id
* @param float $price Additional price
* @param float $weight Additional weight
* @param float $ecotax Additional ecotax
* @param integer $quantity Quantity available
* @param integer $id_image Image id
* @param string $reference Reference
* @param string $ean13 Ean-13 barcode
* @param string $upc Upc barcode
* @param string $minimal_quantity Minimal quantity
* @return array Update result
*/
public function updateProductAttribute($id_product_attribute, $wholesale_price, $price, $weight, $unit, $ecotax, $quantity, $id_images, $reference, $supplier_reference, $ean13, $default, $location = NULL, $upc = NULL, $minimal_quantity)
{
Db::getInstance()->Execute('
DELETE FROM `' . _DB_PREFIX_ . 'product_attribute_combination`
WHERE `id_product_attribute` = ' . (int) $id_product_attribute);
$price = str_replace(',', '.', $price);
$weight = str_replace(',', '.', $weight);
$data = array('wholesale_price' => (double) $wholesale_price, 'price' => (double) $price, 'ecotax' => (double) $ecotax, 'weight' => $weight ? (double) $weight : 0, 'unit_price_impact' => $unit ? (double) $unit : 0, 'reference' => pSQL($reference), 'supplier_reference' => pSQL($supplier_reference), 'location' => pSQL($location), 'ean13' => pSQL($ean13), 'upc' => pSQL($upc), 'default_on' => (int) $default, 'minimal_quantity' => (int) $minimal_quantity);
if ($quantity) {
$data['quantity'] = (int) $quantity;
}
if (!Db::getInstance()->AutoExecute(_DB_PREFIX_ . 'product_attribute', $data, 'UPDATE', '`id_product_attribute` = ' . (int) $id_product_attribute) or !Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'product_attribute_image` WHERE `id_product_attribute` = ' . (int) $id_product_attribute)) {
return false;
}
if ($quantity) {
Hook::updateProductAttribute($id_product_attribute);
}
Product::updateDefaultAttribute($this->id);
if (empty($id_images)) {
return true;
}
$query = 'INSERT INTO `' . _DB_PREFIX_ . 'product_attribute_image` (`id_product_attribute`, `id_image`) VALUES ';
foreach ($id_images as $id_image) {
$query .= '(' . (int) $id_product_attribute . ', ' . (int) $id_image . '), ';
}
$query = trim($query, ', ');
return Db::getInstance()->Execute($query);
}
示例3: updateProductAttribute
/**
* Update a product attribute
*
* @param integer $id_product_attribute Product attribute id
* @param float $price Additional price
* @param float $weight Additional weight
* @param float $ecotax Additional ecotax
* @param integer $quantity Quantity available
* @param integer $id_image Image id
* @param string $reference Reference
* @param string $ean13 Ean-13 barcode
* @return array Update result
*/
public function updateProductAttribute($id_product_attribute, $wholesale_price, $price, $weight, $ecotax, $quantity, $id_images, $reference, $supplier_reference, $ean13, $default, $location = NULL)
{
Db::getInstance()->Execute('
DELETE FROM `' . _DB_PREFIX_ . 'product_attribute_combination`
WHERE `id_product_attribute` = ' . intval($id_product_attribute));
$price = str_replace(',', '.', $price);
$weight = str_replace(',', '.', $weight);
$data = array('wholesale_price' => floatval($wholesale_price), 'price' => floatval($price), 'ecotax' => floatval($ecotax), 'quantity' => intval($quantity), 'weight' => $weight ? floatval($weight) : 0, 'reference' => pSQL($reference), 'supplier_reference' => pSQL($supplier_reference), 'location' => pSQL($location), 'ean13' => pSQL($ean13), 'default_on' => intval($default));
if (!Db::getInstance()->AutoExecute(_DB_PREFIX_ . 'product_attribute', $data, 'UPDATE', '`id_product_attribute` = ' . intval($id_product_attribute)) or !Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'product_attribute_image` WHERE `id_product_attribute` = ' . intval($id_product_attribute))) {
return false;
}
Hook::updateProductAttribute($id_product_attribute);
if (empty($id_images)) {
return true;
}
$query = 'INSERT INTO `' . _DB_PREFIX_ . 'product_attribute_image` (`id_product_attribute`, `id_image`) VALUES ';
foreach ($id_images as $id_image) {
$query .= '(' . intval($id_product_attribute) . ', ' . intval($id_image) . '), ';
}
$query = trim($query, ', ');
return Db::getInstance()->Execute($query);
}