本文整理汇总了PHP中GroupReduction类的典型用法代码示例。如果您正苦于以下问题:PHP GroupReduction类的具体用法?PHP GroupReduction怎么用?PHP GroupReduction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GroupReduction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assignPriceAndTax
/**
* Assign price and tax to the template
*/
protected function assignPriceAndTax()
{
die('coucou');
$id_customer = isset($this->context->customer) ? (int) $this->context->customer->id : 0;
$id_group = (int) Group::getCurrent()->id;
$id_country = $id_customer ? (int) Customer::getCurrentCountry($id_customer) : (int) Tools::getCountry();
$group_reduction = GroupReduction::getValueForProduct($this->product->id, $id_group);
if ($group_reduction === false) {
$group_reduction = Group::getReduction((int) $this->context->cookie->id_customer) / 100;
}
// Tax
$tax = (double) $this->product->getTaxesRate(new Address((int) $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
$this->context->smarty->assign('tax_rate', $tax);
$product_price_with_tax = Product::getPriceStatic($this->product->id, true, null, 6) * 10;
if (Product::$_taxCalculationMethod == PS_TAX_INC) {
$product_price_with_tax = Tools::ps_round($product_price_with_tax, 2);
}
$product_price_without_eco_tax = (double) $product_price_with_tax - $this->product->ecotax;
$ecotax_rate = (double) Tax::getProductEcotaxRate($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$ecotax_tax_amount = Tools::ps_round($this->product->ecotax, 2);
if (Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) {
$ecotax_tax_amount = Tools::ps_round($ecotax_tax_amount * (1 + $ecotax_rate / 100), 2);
}
$id_currency = (int) $this->context->cookie->id_currency;
$id_product = (int) $this->product->id;
$id_shop = $this->context->shop->id;
$quantity_discounts = SpecificPrice::getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, null, true, (int) $this->context->customer->id);
foreach ($quantity_discounts as &$quantity_discount) {
if ($quantity_discount['id_product_attribute']) {
$combination = new Combination((int) $quantity_discount['id_product_attribute']);
$attributes = $combination->getAttributesName((int) $this->context->language->id);
foreach ($attributes as $attribute) {
$quantity_discount['attributes'] = $attribute['name'] . ' - ';
}
$quantity_discount['attributes'] = rtrim($quantity_discount['attributes'], ' - ');
}
if ((int) $quantity_discount['id_currency'] == 0 && $quantity_discount['reduction_type'] == 'amount') {
$quantity_discount['reduction'] = Tools::convertPriceFull($quantity_discount['reduction'], null, Context::getContext()->currency);
}
}
$product_price = $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false) * 10;
$address = new Address($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$this->context->smarty->assign(array('quantity_discounts' => $this->formatQuantityDiscounts($quantity_discounts, $product_price, (double) $tax, $ecotax_tax_amount), 'ecotax_tax_inc' => $ecotax_tax_amount, 'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2), 'ecotaxTax_rate' => $ecotax_rate, 'productPriceWithoutEcoTax' => (double) $product_price_without_eco_tax, 'group_reduction' => $group_reduction, 'no_tax' => Tax::excludeTaxeOption() || !$this->product->getTaxesRate($address), 'ecotax' => !count($this->errors) && $this->product->ecotax > 0 ? Tools::convertPrice((double) $this->product->ecotax) : 0, 'tax_enabled' => Configuration::get('PS_TAX') && !Configuration::get('AEUC_LABEL_TAX_INC_EXC'), 'customer_group_without_tax' => Group::getPriceDisplayMethod($this->context->customer->id_default_group)));
}
示例2: setProductReduction
public static function setProductReduction($id_product, $id_group = null, $id_category, $reduction = null)
{
$res = true;
GroupReduction::deleteProductReduction((int) $id_product);
$reductions = GroupReduction::getGroupsByCategoryId((int) $id_category);
if ($reductions) {
foreach ($reductions as $reduction) {
$res &= Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'product_group_reduction_cache` (`id_product`, `id_group`, `reduction`)
VALUES (' . (int) $id_product . ', ' . (int) $reduction['id_group'] . ', ' . (double) $reduction['reduction'] . ')');
}
}
return $res;
}
示例3: priceCalculation
//.........这里部分代码省略.........
$product_attribute_label = 'NULL';
} else {
$product_attribute_label = $id_product_attribute === false ? 'false' : $id_product_attribute;
}
$cacheId = $id_product . '-' . $id_shop . '-' . $id_currency . '-' . $id_country . '-' . $id_state . '-' . $id_county . '-' . $id_group . '-' . $quantity . '-' . $product_attribute_label . '-' . ($use_tax ? '1' : '0') . '-' . $decimals . '-' . ($only_reduc ? '1' : '0') . '-' . ($use_reduc ? '1' : '0') . '-' . $with_ecotax . '-' . (int) $id_affiliate;
// Cache for specific prices
$cacheId3 = $id_product . '-' . $id_shop . '-' . $id_currency . '-' . $id_country . '-' . $id_group . '-' . $quantity;
// reference parameter is filled before any returns
$specific_price = SpecificPrice::getSpecificPrice((int) $id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity, $id_affiliate);
if (isset(self::$_prices[$cacheId])) {
return self::$_prices[$cacheId];
}
// fetch price & attribute price
$cacheId2 = $id_product . '-' . $id_product_attribute;
if (!isset(self::$_pricesLevel2[$cacheId2])) {
self::$_pricesLevel2[$cacheId2] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT p.`price`,
' . ($id_product_attribute ? 'pa.`price`' : 'IFNULL((SELECT pa.price FROM `' . _DB_PREFIX_ . 'product_attribute` pa WHERE id_product = ' . (int) $id_product . ' AND default_on = 1), 0)') . ' AS attribute_price,
p.`ecotax`
' . ($id_product_attribute ? ', pa.`ecotax` AS attribute_ecotax' : '') . '
FROM `' . _DB_PREFIX_ . 'product` p
' . ($id_product_attribute ? 'LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON pa.`id_product_attribute` = ' . (int) $id_product_attribute : '') . '
WHERE p.`id_product` = ' . (int) $id_product);
}
$result = self::$_pricesLevel2[$cacheId2];
$price = (double) (!$specific_price or $specific_price['price'] == 0) ? $result['price'] : $specific_price['price'];
// convert only if the specific price is in the default currency (id_currency = 0)
if (!$specific_price or !($specific_price['price'] > 0 and $specific_price['id_currency'])) {
$price = Tools::convertPrice($price, $id_currency);
}
// Attribute price
$attribute_price = Tools::convertPrice(array_key_exists('attribute_price', $result) ? (double) $result['attribute_price'] : 0, $id_currency);
if ($id_product_attribute !== false) {
// If you want the default combination, please use NULL value instead
$price += $attribute_price;
}
// TaxRate calculation
$tax_rate = Tax::getProductTaxRateViaRules((int) $id_product, (int) $id_country, (int) $id_state, (int) $id_county);
if ($tax_rate === false) {
$tax_rate = 0;
}
// Add Tax
if ($use_tax) {
$price = $price * (1 + $tax_rate / 100);
}
$price = Tools::ps_round($price, $decimals);
// Reduction
$reduc = 0;
if (($only_reduc or $use_reduc) and $specific_price) {
if ($specific_price['reduction_type'] == 'amount') {
$reduction_amount = $specific_price['reduction'];
if (!$specific_price['id_currency']) {
$reduction_amount = Tools::convertPrice($reduction_amount, $id_currency);
}
$reduc = Tools::ps_round(!$use_tax ? $reduction_amount / (1 + $tax_rate / 100) : $reduction_amount, $decimals);
} else {
$reduc = Tools::ps_round($price * $specific_price['reduction'], $decimals);
}
}
if ($only_reduc && !empty($b1g1)) {
return 0;
} else {
if ($only_reduc) {
return $reduc;
}
}
if ($use_reduc) {
$price -= $reduc;
}
// Group reduction
if ($reductionFromCategory = (double) GroupReduction::getValueForProduct($id_product, $id_group)) {
$price -= $price * $reductionFromCategory;
} else {
// apply group reduction if there is no group reduction for this category
$price *= (100 - Group::getReductionByIdGroup($id_group)) / 100;
}
$price = Tools::ps_round($price, $decimals);
// Eco Tax
if (($result['ecotax'] or isset($result['attribute_ecotax'])) and $with_ecotax) {
$ecotax = $result['ecotax'];
if (isset($result['attribute_ecotax']) && $result['attribute_ecotax'] > 0) {
$ecotax = $result['ecotax'];
}
if ($id_currency) {
$ecotax = Tools::convertPrice($ecotax, $id_currency);
}
if ($use_tax) {
$taxRate = TaxRulesGroup::getTaxesRate((int) Configuration::get('PS_ECOTAX_TAX_RULES_GROUP_ID'), (int) $id_country, (int) $id_state, (int) $id_county);
$price += $ecotax * (1 + $taxRate / 100);
} else {
$price += $ecotax;
}
}
$price = Tools::ps_round($price, $decimals);
if ($price < 0) {
$price = 0;
}
self::$_prices[$cacheId] = $price;
return self::$_prices[$cacheId];
}
示例4: postProcess
//.........这里部分代码省略.........
if (!Validate::isGenericName($attachment->file_name)) {
$this->_errors[] = Tools::displayError('Invalid file name');
}
if (Tools::strlen($attachment->file_name) > 128) {
$this->_errors[] = Tools::displayError('File name too long');
}
if (!sizeof($this->_errors)) {
$attachment->add();
Tools::redirectAdmin($currentIndex . '&id_product=' . (int) Tools::getValue($this->identifier) . '&id_category=' . (int) Tools::getValue('id_category') . '&addproduct&conf=4&tabs=6&token=' . ($token ? $token : $this->token));
} else {
$this->_errors[] = Tools::displayError('Invalid file');
}
}
}
} else {
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
}
} elseif (Tools::isSubmit('submitAttachments')) {
if ($this->tabAccess['edit'] === '1') {
if ($id = (int) Tools::getValue($this->identifier)) {
if (Attachment::attachToProduct($id, $_POST['attachments'])) {
Tools::redirectAdmin($currentIndex . '&id_product=' . (int) $id . (isset($_POST['id_category']) ? '&id_category=' . (int) $_POST['id_category'] : '') . '&conf=4&add' . $this->table . '&tabs=6&token=' . ($token ? $token : $this->token));
}
}
}
} elseif (isset($_GET['duplicate' . $this->table])) {
if ($this->tabAccess['add'] === '1') {
if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) {
$id_product_old = $product->id;
unset($product->id);
unset($product->id_product);
$product->indexed = 0;
$product->active = 0;
if ($product->add() and Category::duplicateProductCategories($id_product_old, $product->id) and ($combinationImages = Product::duplicateAttributes($id_product_old, $product->id)) !== false and GroupReduction::duplicateReduction($id_product_old, $product->id) and Product::duplicateAccessories($id_product_old, $product->id) and Product::duplicateFeatures($id_product_old, $product->id) and Product::duplicateSpecificPrices($id_product_old, $product->id) and Pack::duplicate($id_product_old, $product->id) and Product::duplicateCustomizationFields($id_product_old, $product->id) and Product::duplicateTags($id_product_old, $product->id) and Product::duplicateDownload($id_product_old, $product->id)) {
if ($product->hasAttributes()) {
Product::updateDefaultAttribute($product->id);
}
if (!Tools::getValue('noimage') and !Image::duplicateProductImages($id_product_old, $product->id, $combinationImages)) {
$this->_errors[] = Tools::displayError('An error occurred while copying images.');
} else {
Hook::addProduct($product);
Search::indexation(false, $product->id);
Tools::redirectAdmin($currentIndex . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&conf=19&token=' . ($token ? $token : $this->token));
}
} else {
$this->_errors[] = Tools::displayError('An error occurred while creating object.');
}
}
} else {
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
}
} elseif (isset($_GET['status']) and Tools::getValue($this->identifier)) {
if ($this->tabAccess['edit'] === '1') {
if (Validate::isLoadedObject($object = $this->loadObject())) {
if ($object->toggleStatus()) {
Tools::redirectAdmin($currentIndex . '&conf=5' . (($id_category = !empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1' and Tools::getValue('id_product')) ? '&id_category=' . $id_category : '') . '&token=' . $token);
} else {
$this->_errors[] = Tools::displayError('An error occurred while updating status.');
}
} else {
$this->_errors[] = Tools::displayError('An error occurred while updating status for object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
}
} else {
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
} elseif (isset($_GET['delete' . $this->table])) {
示例5: getGroupReducedPrice
public static function getGroupReducedPrice($id_product, $id_group, $price)
{
$reduction_from_category = GroupReduction::getValueForProduct($id_product, $id_group);
if ($reduction_from_category !== false) {
$price -= $price * (double) $reduction_from_category;
} else {
$price *= (100 - Group::getReductionByIdGroup($id_group)) / 100;
}
return $price;
}
示例6: delete
public function delete()
{
if ((int) $this->id === 0 || (int) $this->id === (int) Configuration::get('PS_ROOT_CATEGORY')) {
return false;
}
$this->clearCache();
$deleted_children = $all_cat = $this->getAllChildren();
$all_cat[] = $this;
foreach ($all_cat as $cat) {
/** @var Category $cat */
$cat->deleteLite();
if (!$this->hasMultishopEntries()) {
$cat->deleteImage();
$cat->cleanGroups();
$cat->cleanAssoProducts();
// Delete associated restrictions on cart rules
CartRule::cleanProductRuleIntegrity('categories', array($cat->id));
Category::cleanPositions($cat->id_parent);
/* Delete Categories in GroupReduction */
if (GroupReduction::getGroupsReductionByCategoryId((int) $cat->id)) {
GroupReduction::deleteCategory($cat->id);
}
}
}
/* Rebuild the nested tree */
if (!$this->hasMultishopEntries() && (!isset($this->doNotRegenerateNTree) || !$this->doNotRegenerateNTree)) {
Category::regenerateEntireNtree();
}
Hook::exec('actionCategoryDelete', array('category' => $this, 'deleted_children' => $deleted_children));
return true;
}
示例7: setProductReduction
public static function setProductReduction($id_product, $id_group = null, $id_category = null, $reduction = null)
{
$res = true;
GroupReduction::deleteProductReduction((int) $id_product);
$categories = Product::getProductCategories((int) $id_product);
if ($categories) {
foreach ($categories as $category) {
$reductions = GroupReduction::getGroupsByCategoryId((int) $category);
if ($reductions) {
foreach ($reductions as $reduction) {
$current_group_reduction = new GroupReduction((int) $reduction['id_group_reduction']);
$res &= $current_group_reduction->_setCache();
}
}
}
}
return $res;
}
示例8: setGroupReduction
/**
* Set Group reduction if needed
*/
public function setGroupReduction()
{
$row = GroupReduction::getGroupByCategoryId((int) $this->id_category_default);
if (!$row) {
if (!GroupReduction::deleteProductReduction((int) $this->id)) {
return false;
}
} else {
if (!GroupReduction::setProductReduction((int) $this->id, $row['id_group'], (int) $this->id_category_default, (double) $row['reduction'])) {
return false;
}
}
return true;
}
示例9: validateOrder
//.........这里部分代码省略.........
if (!isset($store_all_taxes[$res->id])) {
$store_all_taxes[$res->id] = array();
$store_all_taxes[$res->id]['amount'] = 0;
}
$store_all_taxes[$res->id]['name'] = $res->name[(int) $order->id_lang];
$store_all_taxes[$res->id]['rate'] = $res->rate;
$unit_tax_amount = $tmp_price * ($res->rate * 0.01);
$tmp_price = $tmp_price + $unit_tax_amount;
$store_all_taxes[$res->id]['amount'] += $unit_tax_amount * $product['cart_quantity'];
}
}
/* End */
// Add some informations for virtual products
$deadline = '0000-00-00 00:00:00';
$download_hash = null;
if ($id_product_download = ProductDownload::getIdFromIdProduct((int) $product['id_product'])) {
$productDownload = new ProductDownload((int) $id_product_download);
$deadline = $productDownload->getDeadLine();
$download_hash = $productDownload->getHash();
}
// Exclude VAT
if (!_PS_TAX_) {
$product['tax'] = 0;
$product['rate'] = 0;
$tax_rate = 0;
} else {
$tax_rate = Tax::getProductTaxRate((int) $product['id_product'], $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
}
$ecotaxTaxRate = 0;
if (!empty($product['ecotax'])) {
$ecotaxTaxRate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
}
$product_price = (double) Product::getPriceStatic((int) $product['id_product'], false, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL, Product::getTaxCalculationMethod((int) $order->id_customer) == PS_TAX_EXC ? 2 : 6, NULL, false, false, $product['cart_quantity'], false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}, $specificPrice, false, false);
$group_reduction = (double) GroupReduction::getValueForProduct((int) $product['id_product'], $customer->id_default_group) * 100;
if (!$group_reduction) {
$group_reduction = (double) Group::getReduction((int) $order->id_customer);
}
$quantityDiscount = SpecificPrice::getQuantityDiscount((int) $product['id_product'], Shop::getCurrentShop(), (int) $cart->id_currency, (int) $vat_address->id_country, (int) $customer->id_default_group, (int) $product['cart_quantity']);
$unitPrice = Product::getPriceStatic((int) $product['id_product'], true, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, 2, NULL, false, true, 1, false, (int) $order->id_customer, NULL, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$quantityDiscountValue = $quantityDiscount ? (Product::getTaxCalculationMethod((int) $order->id_customer) == PS_TAX_EXC ? Tools::ps_round($unitPrice, 2) : $unitPrice) - $quantityDiscount['price'] * (1 + $tax_rate / 100) : 0.0;
$query .= '(' . (int) $order->id . ',
' . (int) $product['id_product'] . ',
' . (isset($product['id_product_attribute']) ? (int) $product['id_product_attribute'] : 'NULL') . ',
\'' . pSQL($product['name'] . ((isset($product['attributes']) and $product['attributes'] != NULL) ? ' - ' . $product['attributes'] : '')) . '\',
' . (int) $product['cart_quantity'] . ',
' . $quantityInStock . ',
' . $product_price . ',
' . (double) (($specificPrice and $specificPrice['reduction_type'] == 'percentage') ? $specificPrice['reduction'] * 100 : 0.0) . ',
' . (double) (($specificPrice and $specificPrice['reduction_type'] == 'amount') ? !$specificPrice['id_currency'] ? Tools::convertPrice($specificPrice['reduction'], $order->id_currency) : $specificPrice['reduction'] : 0.0) . ',
' . $group_reduction . ',
' . $quantityDiscountValue . ',
' . (empty($product['ean13']) ? 'NULL' : '\'' . pSQL($product['ean13']) . '\'') . ',
' . (empty($product['upc']) ? 'NULL' : '\'' . pSQL($product['upc']) . '\'') . ',
' . (empty($product['reference']) ? 'NULL' : '\'' . pSQL($product['reference']) . '\'') . ',
' . (empty($product['supplier_reference']) ? 'NULL' : '\'' . pSQL($product['supplier_reference']) . '\'') . ',
' . (double) ($product['id_product_attribute'] ? $product['weight_attribute'] : $product['weight']) . ',
\'' . (empty($tax_rate) ? '' : pSQL($product['tax'])) . '\',
' . (double) $tax_rate . ',
' . (double) Tools::convertPrice(floatval($product['ecotax']), intval($order->id_currency)) . ',
' . (double) $ecotaxTaxRate . ',
' . (($specificPrice and $specificPrice['from_quantity'] > 1) ? 1 : 0) . ',
\'' . pSQL($deadline) . '\',
\'' . pSQL($download_hash) . '\'),';
$customizationQuantity = 0;
if (isset($customizedDatas[$product['id_product']][$product['id_product_attribute']])) {
$customizationText = '';
示例10: postProcess
public function postProcess()
{
global $currentIndex;
$token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
if (Tools::isSubmit('deleteGroupReduction')) {
if ($this->tabAccess['delete'] === '1') {
if (!($id_group_reduction = Tools::getValue('id_group_reduction'))) {
$this->_errors[] = Tools::displayError('Invalid group reduction ID');
} else {
$groupReduction = new GroupReduction((int) $id_group_reduction);
if (!$groupReduction->delete()) {
$this->_errors[] = Tools::displayError('An error occurred while deleting the group reduction');
} else {
Tools::redirectAdmin($currentIndex . '&update' . $this->table . '&id_group=' . (int) Tools::getValue('id_group') . '&conf=1&token=' . $token);
}
}
} else {
$this->_errors[] = Tools::displayError('You do not have permission to delete here.');
}
}
if (Tools::isSubmit('submitAddGroupReduction')) {
if ($this->tabAccess['add'] === '1') {
if (!($obj = $this->loadObject())) {
return;
}
$groupReduction = new GroupReduction();
if (!($id_category = Tools::getValue('id_category')) or !Validate::isUnsignedId($id_category)) {
$this->_errors[] = Tools::displayError('Wrong category ID');
} elseif (!($reduction = Tools::getValue('reductionByCategory')) or !Validate::isPrice($reduction)) {
$this->_errors[] = Tools::displayError('Invalid reduction (must be a percentage)');
} elseif (Tools::getValue('reductionByCategory') > 100 or Tools::getValue('reductionByCategory') < 0) {
$this->_errors[] = Tools::displayError('Reduction value is incorrect');
} elseif (GroupReduction::doesExist((int) $obj->id, $id_category)) {
$this->_errors[] = Tools::displayError('A reduction already exists for this category.');
} else {
$groupReduction->id_category = (int) $id_category;
$groupReduction->id_group = (int) $obj->id;
$groupReduction->reduction = (double) $reduction / 100;
if (!$groupReduction->add()) {
$this->_errors[] = Tools::displayError('An error occurred while adding a category group reduction.');
} else {
Tools::redirectAdmin($currentIndex . '&update' . $this->table . '&id_group=' . (int) Tools::getValue('id_group') . '&conf=3&token=' . $this->token);
}
}
} else {
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
}
}
if (Tools::isSubmit('submitAddgroup')) {
if ($this->tabAccess['add'] === '1') {
if (Tools::getValue('reduction') > 100 or Tools::getValue('reduction') < 0) {
$this->_errors[] = Tools::displayError('Reduction value is incorrect');
} else {
$id_group_reductions = Tools::getValue('gr_id_group_reduction');
$reductions = Tools::getValue('gr_reduction');
if ($id_group_reductions) {
foreach ($id_group_reductions as $key => $id_group_reduction) {
if (!Validate::isUnsignedId($id_group_reductions[$key]) or !Validate::isPrice($reductions[$key])) {
$this->_errors[] = Tools::displayError('Invalid reduction (must be a percentage)');
} elseif ($reductions[$key] > 100 or $reductions[$key] < 0) {
$this->_errors[] = Tools::displayError('Reduction value is incorrect');
} else {
$groupReduction = new GroupReduction((int) $id_group_reductions[$key]);
$groupReduction->reduction = $reductions[$key] / 100;
if (!$groupReduction->update()) {
$this->_errors[] = Tools::displayError('Cannot update group reductions');
}
}
}
}
if (!sizeof($this->_errors)) {
parent::postProcess();
}
}
} else {
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
}
} elseif (isset($_GET['delete' . $this->table])) {
if ($this->tabAccess['delete'] === '1') {
if (Validate::isLoadedObject($object = $this->loadObject())) {
if ($object->id == 1) {
$this->_errors[] = Tools::displayError('You cannot delete default group.');
} else {
if ($object->delete()) {
Tools::redirectAdmin($currentIndex . '&conf=1&token=' . $token);
}
$this->_errors[] = Tools::displayError('An error occurred during deletion.');
}
} else {
$this->_errors[] = Tools::displayError('An error occurred while deleting object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
}
} else {
$this->_errors[] = Tools::displayError('You do not have permission to delete here.');
}
} else {
parent::postProcess();
}
}
示例11: process
public function process()
{
global $cart, $currency;
parent::process();
if (!Validate::isLoadedObject($this->product)) {
$this->errors[] = Tools::displayError('Product not found');
} else {
if (!$this->product->active and Tools::getValue('adtoken') != Tools::encrypt('PreviewProduct' . $this->product->id) || !file_exists(dirname(__FILE__) . '/../' . Tools::getValue('ad') . '/ajax.php')) {
header('HTTP/1.1 404 page not found');
$this->errors[] = Tools::displayError('Product is no longer available.');
} elseif (!$this->product->checkAccess((int) self::$cookie->id_customer)) {
$this->errors[] = Tools::displayError('You do not have access to this product.');
} else {
self::$smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id));
if (!$this->product->active) {
self::$smarty->assign('adminActionDisplay', true);
}
/* Product pictures management */
require_once 'images.inc.php';
if ($this->product->customizable) {
self::$smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
if (Tools::isSubmit('submitCustomizedDatas')) {
$this->pictureUpload($this->product, $cart);
$this->textRecord($this->product, $cart);
$this->formTargetFormat();
} elseif (isset($_GET['deletePicture']) and !$cart->deletePictureToProduct((int) $this->product->id, (int) Tools::getValue('deletePicture'))) {
$this->errors[] = Tools::displayError('An error occurred while deleting the selected picture');
}
$files = self::$cookie->getFamily('pictures_' . (int) $this->product->id);
$textFields = self::$cookie->getFamily('textFields_' . (int) $this->product->id);
foreach ($textFields as $key => $textField) {
$textFields[$key] = str_replace('<br />', "\n", $textField);
}
self::$smarty->assign(array('pictures' => $files, 'textFields' => $textFields));
}
/* Features / Values */
$features = $this->product->getFrontFeatures((int) self::$cookie->id_lang);
$attachments = $this->product->cache_has_attachments ? $this->product->getAttachments((int) self::$cookie->id_lang) : array();
/* Category */
$category = false;
if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) {
if (isset($regs[2]) and is_numeric($regs[2])) {
if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) {
$category = new Category((int) $regs[2], (int) self::$cookie->id_lang);
}
} elseif (isset($regs[5]) and is_numeric($regs[5])) {
if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) {
$category = new Category((int) $regs[5], (int) self::$cookie->id_lang);
}
}
}
if (!$category) {
$category = new Category($this->product->id_category_default, (int) self::$cookie->id_lang);
}
if (isset($category) and Validate::isLoadedObject($category)) {
self::$smarty->assign(array('path' => Tools::getPath((int) $category->id, $this->product->name, true), 'category' => $category, 'subCategories' => $category->getSubCategories((int) self::$cookie->id_lang, true), 'id_category_current' => (int) $category->id, 'id_category_parent' => (int) $category->id_parent, 'return_category_name' => Tools::safeOutput($category->name)));
} else {
self::$smarty->assign('path', Tools::getPath((int) $this->product->id_category_default, $this->product->name));
}
self::$smarty->assign('return_link', (isset($category->id) and $category->id) ? Tools::safeOutput(self::$link->getCategoryLink($category)) : 'javascript: history.back();');
if (Pack::isPack((int) $this->product->id) and !Pack::isInStock((int) $this->product->id)) {
$this->product->quantity = 0;
}
$id_customer = (isset(self::$cookie->id_customer) and self::$cookie->id_customer) ? (int) self::$cookie->id_customer : 0;
$id_group = $id_customer ? (int) Customer::getDefaultGroupId($id_customer) : _PS_DEFAULT_CUSTOMER_GROUP_;
$id_country = (int) ($id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT'));
$group_reduction = GroupReduction::getValueForProduct($this->product->id, $id_group);
if ($group_reduction == 0) {
$group_reduction = Group::getReduction((int) self::$cookie->id_customer) / 100;
}
// Tax
$tax = (double) Tax::getProductTaxRate((int) $this->product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
self::$smarty->assign('tax_rate', $tax);
$productPriceWithTax = Product::getPriceStatic($this->product->id, true, NULL, 6);
if (Product::$_taxCalculationMethod == PS_TAX_INC) {
$productPriceWithTax = Tools::ps_round($productPriceWithTax, 2);
}
$productPriceWithoutEcoTax = (double) ($productPriceWithTax - $this->product->ecotax);
$ecotax_rate = (double) Tax::getProductEcotaxRate($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$ecotaxTaxAmount = Tools::ps_round($this->product->ecotax, 2);
if (Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) {
$ecotaxTaxAmount = Tools::ps_round($ecotaxTaxAmount * (1 + $ecotax_rate / 100), 2);
}
self::$smarty->assign(array('quantity_discounts' => $this->formatQuantityDiscounts(SpecificPrice::getQuantityDiscounts((int) $this->product->id, (int) Shop::getCurrentShop(), (int) self::$cookie->id_currency, $id_country, $id_group), $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false), (double) $tax), 'product' => $this->product, 'ecotax_tax_inc' => $ecotaxTaxAmount, 'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2), 'ecotaxTax_rate' => $ecotax_rate, 'homeSize' => Image::getSize('home'), 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, self::$cookie->id_lang), 'token' => Tools::getToken(false), 'productPriceWithoutEcoTax' => (double) $productPriceWithoutEcoTax, 'features' => $features, 'attachments' => $attachments, 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'group_reduction' => 1 - $group_reduction, 'col_img_dir' => _PS_COL_IMG_DIR_));
self::$smarty->assign(array('HOOK_EXTRA_LEFT' => Module::hookExec('extraLeft'), 'HOOK_EXTRA_RIGHT' => Module::hookExec('extraRight'), 'HOOK_PRODUCT_OOS' => Hook::productOutOfStock($this->product), 'HOOK_PRODUCT_FOOTER' => Hook::productFooter($this->product, $category), 'HOOK_PRODUCT_ACTIONS' => Module::hookExec('productActions'), 'HOOK_PRODUCT_TAB' => Module::hookExec('productTab'), 'HOOK_PRODUCT_TAB_CONTENT' => Module::hookExec('productTabContent')));
$images = $this->product->getImages((int) self::$cookie->id_lang);
$productImages = array();
foreach ($images as $k => $image) {
if ($image['cover']) {
self::$smarty->assign('mainImage', $images[0]);
$cover = $image;
$cover['id_image'] = Configuration::get('PS_LEGACY_IMAGES') ? $this->product->id . '-' . $image['id_image'] : $image['id_image'];
$cover['id_image_only'] = (int) $image['id_image'];
}
$productImages[(int) $image['id_image']] = $image;
}
if (!isset($cover)) {
$cover = array('id_image' => Language::getIsoById(self::$cookie->id_lang) . '-default', 'legend' => 'No picture', 'title' => 'No picture');
}
$size = Image::getSize('large');
//.........这里部分代码省略.........
示例12: getTemplateVarProduct
public function getTemplateVarProduct()
{
$productSettings = $this->getProductPresentationSettings();
$product = $this->objectPresenter->present($this->product);
$product['id_product'] = (int) $this->product->id;
$product['out_of_stock'] = (int) $this->product->out_of_stock;
$product['new'] = (int) $this->product->new;
$product['id_product_attribute'] = (int) Tools::getValue('id_product_attribute');
$product['minimal_quantity'] = $this->getProductMinimalQuantity($product);
$product['quantity_wanted'] = $this->getRequiredQuantity($product);
$product_full = Product::getProductProperties($this->context->language->id, $product, $this->context);
$product_full = $this->addProductCustomizationData($product_full);
$product_full['show_quantities'] = (bool) (Configuration::get('PS_DISPLAY_QTIES') && Configuration::get('PS_STOCK_MANAGEMENT') && $this->product->quantity > 0 && $this->product->available_for_order && !Configuration::isCatalogMode());
$product_full['quantity_label'] = $this->product->quantity > 1 ? $this->trans('Items', array(), 'Shop.Theme.Catalog') : $this->trans('Item', array(), 'Shop.Theme.Catalog');
$product_full['quantity_discounts'] = $this->quantity_discounts;
if ($product_full['unit_price_ratio'] > 0) {
$unitPrice = $productSettings->include_taxes ? $product_full['price'] : $product_full['price_tax_exc'];
$product_full['unit_price'] = $unitPrice / $product_full['unit_price_ratio'];
}
$group_reduction = GroupReduction::getValueForProduct($this->product->id, (int) Group::getCurrent()->id);
if ($group_reduction === false) {
$group_reduction = Group::getReduction((int) $this->context->cookie->id_customer) / 100;
}
$product_full['customer_group_discount'] = $group_reduction;
$presenter = $this->getProductPresenter();
return $presenter->present($productSettings, $product_full, $this->context->language);
}
示例13: initContent
public function initContent()
{
if (!$this->ajax) {
parent::initContent();
}
// parent::initContent();
$this->setTemplate(_PS_THEME_DIR_ . 'category.tpl');
if (!$this->customer_access) {
return;
}
if (isset($this->context->cookie->id_compare)) {
$this->context->smarty->assign('compareProducts', CompareProduct::getCompareProducts((int) $this->context->cookie->id_compare));
}
$this->productSort();
// Product sort must be called before assignProductList()
$this->assignScenes();
$this->assignSubcategories();
$this->assignProductList();
$products = isset($this->cat_products) && $this->cat_products ? $this->cat_products : null;
$combinations = array();
if ($products !== NULL) {
foreach ($products as &$pro) {
$product_obj = new Product($pro['id_product'], $this->context->language->id);
$pro['groups'] = $product_obj->getProductCombinationsGroups($pro['id_product']);
$combinations[$pro['id_product']] = $product_obj->getProductAttributeCombinations($pro['id_product']);
$id_group = (int) Group::getCurrent()->id;
$group_reduction = GroupReduction::getValueForProduct($pro['id_product'], $id_group);
if ($group_reduction === false) {
$group_reduction = Group::getReduction((int) $this->context->cookie->id_customer) / 100;
}
$pro['group_reduction'] = $group_reduction;
$address = new Address($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$pro['no_tax'] = Tax::excludeTaxeOption() || !$product_obj->getTaxesRate($address);
$pro['customer_group_without_tax'] = Group::getPriceDisplayMethod($this->context->customer->id_default_group);
$tax = (double) $product_obj->getTaxesRate(new Address((int) $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
$pro['tax_rate'] = $tax;
$pro['unit_price_ratio'] = $product_obj->unit_price_ratio;
$ecotax_rate = (double) Tax::getProductEcotaxRate($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$pro['ecotaxTax_rate'] = $ecotax_rate;
}
}
$this->context->smarty->assign(array('category' => $this->category, 'description_short' => Tools::truncateString($this->category->description, 350), 'products' => $products, 'id_category' => (int) $this->category->id, 'id_category_parent' => (int) $this->category->id_parent, 'return_category_name' => Tools::safeOutput($this->category->name), 'path' => Tools::getPath($this->category->id), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'categorySize' => Image::getSize(ImageType::getFormatedName('category')), 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), 'thumbSceneSize' => Image::getSize(ImageType::getFormatedName('m_scene')), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), 'allow_oosp' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'comparator_max_item' => (int) Configuration::get('PS_COMPARATOR_MAX_ITEM'), 'suppliers' => Supplier::getSuppliers(), 'body_classes' => array($this->php_self . '-' . $this->category->id, $this->php_self . '-' . $this->category->link_rewrite), 'combinations' => $combinations));
}
示例14: delete
public function delete()
{
if ((int) $this->id === 0 or (int) $this->id === 1) {
return false;
}
$this->clearCache();
/* Get childs categories */
$toDelete = array((int) $this->id);
$this->recursiveDelete($toDelete, (int) $this->id);
$toDelete = array_unique($toDelete);
/* Delete category and its child from database */
$list = sizeof($toDelete) > 1 ? implode(',', array_map('intval', $toDelete)) : (int) $this->id;
Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'category` WHERE `id_category` IN (' . $list . ')');
Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'category_lang` WHERE `id_category` IN (' . $list . ')');
Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'category_product` WHERE `id_category` IN (' . $list . ')');
Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'category_group` WHERE `id_category` IN (' . $list . ')');
self::cleanPositions($this->id_parent);
/* Delete category images and its children images */
$tmpCategory = new Category();
foreach ($toDelete as $id_category) {
$tmpCategory->id = (int) $id_category;
$tmpCategory->deleteImage();
}
/* Delete products which were not in others categories */
$result = Db::getInstance()->ExecuteS('
SELECT `id_product`
FROM `' . _DB_PREFIX_ . 'product`
WHERE `id_product` NOT IN (SELECT `id_product` FROM `' . _DB_PREFIX_ . 'category_product`)');
foreach ($result as $p) {
$product = new Product((int) $p['id_product']);
if (Validate::isLoadedObject($product)) {
$product->delete();
}
}
/* Set category default to 1 where categorie no more exists */
$result = Db::getInstance()->Execute('
UPDATE `' . _DB_PREFIX_ . 'product`
SET `id_category_default` = 1
WHERE `id_category_default`
NOT IN (SELECT `id_category` FROM `' . _DB_PREFIX_ . 'category`)');
/* Rebuild the nested tree */
if (!isset($this->doNotRegenerateNTree) or !$this->doNotRegenerateNTree) {
self::regenerateEntireNtree();
}
Module::hookExec('categoryDeletion', array('category' => $this));
/* Delete Categories in GroupReduction */
foreach ($toDelete as $category) {
if (GroupReduction::getGroupReductionByCategoryId((int) $category)) {
GroupReduction::deleteCategory($category);
}
}
return true;
}
示例15: priceCalculation
//.........这里部分代码省略.........
//$base_price_wt - (($row['reduction'] * $base_price_wt) / 100);
}
} else {
$row['price'] = 0;
//$row['price_wt'];
}
$array_tmp = array('price' => $row['price'], 'ecotax' => !empty($row['ecotax']), 'attribute_price' => isset($row['attribute_price']) ? $row['attribute_price'] : null);
self::$_pricesLevel2[$cache_id_2][(int) $row['id_product_attribute']] = $array_tmp;
if (isset($row['default_on']) && $row['default_on'] == 1) {
self::$_pricesLevel2[$cache_id_2][0] = $array_tmp;
}
}
}
}
if (!isset(self::$_pricesLevel2[$cache_id_2][(int) $id_product_attribute])) {
return;
}
$result = self::$_pricesLevel2[$cache_id_2][(int) $id_product_attribute];
if (!$specific_price || $specific_price['price'] < 0) {
$price = (double) $result['price'];
} else {
$price = (double) $specific_price['price'];
}
if (!$specific_price || !($specific_price['price'] >= 0 && $specific_price['id_currency'])) {
$price = Tools::convertPrice($price, $id_currency);
if (isset($specific_price['price'])) {
$specific_price['price'] = $price;
}
}
if (is_array($result) && (!$specific_price || !$specific_price['id_product_attribute'] || $specific_price['price'] < 0)) {
$attribute_price = Tools::convertPrice($result['attribute_price'] !== null ? (double) $result['attribute_price'] : 0, $id_currency);
if ($id_product_attribute !== false) {
$price += $attribute_price;
}
}
$address->id_country = $id_country;
$address->id_state = $id_state;
$address->postcode = $zipcode;
$tax_manager = TaxManagerFactory::getManager($address, Product::getIdTaxRulesGroupByIdProduct((int) $id_product, $context));
$product_tax_calculator = $tax_manager->getTaxCalculator();
if ($use_tax) {
$price = $product_tax_calculator->addTaxes($price);
}
if (($result['ecotax'] || isset($result['attribute_ecotax'])) && $with_ecotax) {
$ecotax = $result['ecotax'];
if (isset($result['attribute_ecotax']) && $result['attribute_ecotax'] > 0) {
$ecotax = $result['attribute_ecotax'];
}
if ($id_currency) {
$ecotax = Tools::convertPrice($ecotax, $id_currency);
}
if ($use_tax) {
$tax_manager = TaxManagerFactory::getManager($address, (int) Configuration::get('PS_ECOTAX_TAX_RULES_GROUP_ID'));
$ecotax_tax_calculator = $tax_manager->getTaxCalculator();
$price += $ecotax_tax_calculator->addTaxes($ecotax);
} else {
$price += $ecotax;
}
}
$specific_price_reduction = 0;
if (($only_reduc || $use_reduc) && $specific_price) {
if ($specific_price['reduction_type'] == 'amount') {
$reduction_amount = $specific_price['reduction'];
if (!$specific_price['id_currency']) {
$reduction_amount = Tools::convertPrice($reduction_amount, $id_currency);
}
$specific_price_reduction = $reduction_amount;
if (!$use_tax && $specific_price['reduction_tax']) {
$specific_price_reduction = $product_tax_calculator->removeTaxes($specific_price_reduction);
}
if ($use_tax && !$specific_price['reduction_tax']) {
$specific_price_reduction = $product_tax_calculator->addTaxes($specific_price_reduction);
}
} else {
$specific_price_reduction = $price * $specific_price['reduction'];
}
}
if ($use_reduc) {
$price -= $specific_price_reduction;
}
if ($use_group_reduction) {
$reduction_from_category = GroupReduction::getValueForProduct($id_product, $id_group);
if ($reduction_from_category !== false) {
$group_reduction = $price * (double) $reduction_from_category;
} else {
// apply group reduction if there is no group reduction for this category
$group_reduction = ($reduc = Group::getReductionByIdGroup($id_group)) != 0 ? $price * $reduc / 100 : 0;
}
$price -= $group_reduction;
}
if ($only_reduc) {
return Tools::ps_round($specific_price_reduction, $decimals);
}
$price = Tools::ps_round($price, $decimals);
if ($price < 0) {
$price = 0;
}
self::$_prices[$cache_id] = $price;
return self::$_prices[$cache_id];
}