Esempio n. 1
0
 public static function applyRuleToProduct($rule_id, $product_id, $product_attribute_id = null)
 {
     $rule = new JeproshopSpecificPriceRuleModelSpecificPriceRule((int) $rule_id);
     if (!JeproshopValidator::isLoadedObject($rule, 'specific-price_rule_id') || !$product_id) {
         return false;
     }
     $specific_price = new JeproshopSpecificPriceModelSpecificPrice();
     $specific_price->specific_price_rule_id = (int) $rule->specific_price_rule_id;
     $specific_price->product_id = (int) $product_id;
     $specific_price->product_attribute_id = (int) $product_attribute_id;
     $specific_price->customer_id = 0;
     $specific_price->shop_id = (int) $rule->shop_id;
     $specific_price->country_id = (int) $rule->country_id;
     $specific_price->currency_id = (int) $rule->currency_id;
     $specific_price->group_id = (int) $rule->group_id;
     $specific_price->from_quantity = (int) $rule->from_quantity;
     $specific_price->price = (double) $rule->price;
     $specific_price->reduction_type = $rule->reduction_type;
     $specific_price->reduction = $rule->reduction_type == 'percentage' ? $rule->reduction / 100 : (double) $rule->reduction;
     $specific_price->from = $rule->from;
     $specific_price->to = $rule->to;
     return $specific_price->add();
 }
Esempio n. 2
0
 public function processPriceAddition()
 {
     $app = JFactory::getApplication();
     // Check if a specific price has been submitted
     $data = JRequest::get('post');
     $input_data = $data['price_field'];
     $product_id = $app->input->get('product_id');
     $product_attribute_id = $input_data['sp_product_attribute_id'];
     $shop_id = $input_data['sp_shop_id'];
     $currency_id = $input_data['sp_currency_id'];
     $country_id = $input_data['sp_country_id'];
     $group_id = $input_data['sp_group_id'];
     $customer_id = $input_data['sp_customer_id'];
     $price = $input_data['leave_base_price'] ? '-1' : $input_data['sp_price'];
     $from_quantity = $input_data['sp_from_quantity'];
     $reduction = (double) $input_data['sp_reduction'];
     $reduction_type = !$reduction ? 'amount' : $input_data['sp_reduction_type'];
     $from = $input_data['sp_from'];
     if (!$from) {
         $from = '0000-00-00 00:00:00';
     }
     $to = $input_data['sp_to'];
     if (!$to) {
         $to = '0000-00-00 00:00:00';
     }
     if ($reduction_type == 'percentage' && ((double) $reduction <= 0 || (double) $reduction > 100)) {
         $this->context->controller->has_errors = true;
         JError::raiseError(500, 'Submitted reduction value (0-100) is out-of-range');
     } elseif ($this->validateSpecificPrice($shop_id, $currency_id, $country_id, $group_id, $customer_id, $price, $from_quantity, $reduction, $reduction_type, $from, $to, $product_attribute_id)) {
         $specificPrice = new JeproshopSpecificPriceModelSpecificPrice();
         $specificPrice->product_id = (int) $product_id;
         $specificPrice->product_attribute_id = (int) $product_attribute_id;
         $specificPrice->shop_id = (int) $shop_id;
         $specificPrice->currency_id = (int) $currency_id;
         $specificPrice->country_id = (int) $country_id;
         $specificPrice->group_id = (int) $group_id;
         $specificPrice->customer_id = (int) $customer_id;
         $specificPrice->price = (double) $price;
         $specificPrice->from_quantity = (int) $from_quantity;
         $specificPrice->reduction = (double) ($reduction_type == 'percentage' ? $reduction / 100 : $reduction);
         $specificPrice->reduction_type = $reduction_type;
         $specificPrice->from = $from;
         $specificPrice->to = $to;
         if (!$specificPrice->add()) {
             $this->context->controller->has_errors = JText::_('An error occurred while updating the specific price.');
         }
     }
 }