Welcome Guest, Not a member yet? Register   Sign In
flexi cart - A comprehensive shopping cart library for CodeIgniter
#47

[eluser]JoJo17[/eluser]
Hi

This looks to be a great library and just what I need! I am having a little trouble with the discounts though and perhaps I'm not understanding it correctly but I can't get it working how I want.

I want the discounts to be stored in the database and when a user enters the correct code for the discount it gets updated to their cart. What I have is:

In the admin area of the site I have a specific discounts controller and the part that saves the discount codes to the database in the discounts model is thus:

Code:
public function add_discount()
{

//insert into the discount table
$sql_insert = array(
  'disc_code' => $this->input->post('code') ,
  'disc_description' => $this->input->post('description') ,
  'disc_method_fk' => $this->input->post('code_type') ,
  'disc_value_discounted' => $this->input->post('code_value') ,
  'disc_quantity_required' => '0' ,
  'disc_quantity_discounted' => '0' ,
  'disc_value_required' => '0' ,
  'disc_recursive' => '1' ,
  'disc_non_combinable_discount' => '1' ,
  'disc_void_reward_points' => '0' ,
  'disc_force_ship_discount' => '0' ,
  'disc_valid_date' => $this->common_functions->get_timestamp() ,
  'disc_status' => '1' ,
  'disc_order_by' => '1'
);

$discount_id = $this->flexi_cart_admin->insert_db_discount($sql_insert);

  
}
Code:
$this->input->post('code')
is the code to be entered by the end user to apply their discount to their cart
Code:
$this->input->post('description')
is a description of the discount
Code:
$this->input->post('code_type')
the ID of the discount method as from the discount methods table, in my case this will be 7 or 8
Code:
$this->input->post('code_value')
the amount to discount e.g., 10.00
Code:
$this->common_functions->get_timestamp()
this is just some custom code to insert the current date and time

This does add the discount to the discount table.

Within the shopping cart controller I have a function in the method that checks the entered code against the discount table:

Code:
public function promo_code()
{
  
  if ($_POST) :
   $this->flexi = new stdClass;
   $this->load->library('flexi_cart');
   $discount_data = $this->input->post('promo_code');
   $code = $this->flexi_cart->update_discount_codes($discount_data);
   $msg = $this->flexi_cart->get_messages();
  endif;
  echo $msg;
  
}

but it always returns:

Discount code(s) is invalid.

Discounts were not updated.

even though the code is in the discount table. I just want to be able to set a discount of either a flat fee or percentage on the cart total (excl. shipping).

I'm obviously misunderstanding this somewhere along the line and would appreciate if you could point me in the right direction please!


Messages In This Thread
flexi cart - A comprehensive shopping cart library for CodeIgniter - by El Forum - 09-20-2012, 02:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB