/** * processProductSpecificPrice * Add/Update specific price * * @param int $id_product * @param array $specificPriceValues the posted values * * @return \AdminProductsControllerCore instance */ public function processProductSpecificPrice($id_product, $specificPriceValues) { $id_product_attribute = $specificPriceValues['sp_id_product_attribute']; $id_shop = $specificPriceValues['sp_id_shop'] ? $specificPriceValues['sp_id_shop'] : 0; $id_currency = $specificPriceValues['sp_id_currency'] ? $specificPriceValues['sp_id_currency'] : 0; $id_country = $specificPriceValues['sp_id_country'] ? $specificPriceValues['sp_id_country'] : 0; $id_group = $specificPriceValues['sp_id_group'] ? $specificPriceValues['sp_id_group'] : 0; $id_customer = !empty($specificPriceValues['sp_id_customer']['data']) ? $specificPriceValues['sp_id_customer']['data'][0] : 0; $price = isset($specificPriceValues['leave_bprice']) ? '-1' : $specificPriceValues['sp_price']; $from_quantity = $specificPriceValues['sp_from_quantity']; $reduction = (double) $specificPriceValues['sp_reduction']; $reduction_tax = $specificPriceValues['sp_reduction_tax']; $reduction_type = !$reduction ? 'amount' : $specificPriceValues['sp_reduction_type']; $reduction_type = $reduction_type == '-' ? 'amount' : $reduction_type; $from = $specificPriceValues['sp_from']; if (!$from) { $from = '0000-00-00 00:00:00'; } $to = $specificPriceValues['sp_to']; if (!$to) { $to = '0000-00-00 00:00:00'; } if ($price == '-1' && (double) $reduction == '0') { $this->errors[] = 'No reduction value has been submitted'; } elseif ($to != '0000-00-00 00:00:00' && strtotime($to) < strtotime($from)) { $this->errors[] = 'Invalid date range'; } elseif ($reduction_type == 'percentage' && ((double) $reduction <= 0 || (double) $reduction > 100)) { $this->errors[] = 'Submitted reduction value (0-100) is out-of-range'; } elseif ($this->validateSpecificPrice($id_product, $id_shop, $id_currency, $id_country, $id_group, $id_customer, $price, $from_quantity, $reduction, $reduction_type, $from, $to, $id_product_attribute)) { $specificPrice = new \SpecificPriceCore(); $specificPrice->id_product = (int) $id_product; $specificPrice->id_product_attribute = (int) $id_product_attribute; $specificPrice->id_shop = (int) $id_shop; $specificPrice->id_currency = (int) $id_currency; $specificPrice->id_country = (int) $id_country; $specificPrice->id_group = (int) $id_group; $specificPrice->id_customer = (int) $id_customer; $specificPrice->price = (double) $price; $specificPrice->from_quantity = (int) $from_quantity; $specificPrice->reduction = (double) ($reduction_type == 'percentage' ? $reduction / 100 : $reduction); $specificPrice->reduction_tax = $reduction_tax; $specificPrice->reduction_type = $reduction_type; $specificPrice->from = $from; $specificPrice->to = $to; if (!$specificPrice->add()) { $this->errors[] = 'An error occurred while updating the specific price.'; } } return $this->errors; }