EllisLab text mark
Advanced Search
3 of 10
3
   
flexi cart - A comprehensive shopping cart library for CodeIgniter
Posted: 20 August 2012 11:58 PM   [ Ignore ]   [ # 41 ]   [ Rating: 0 ]
Avatar
Joined: 2012-06-09
82 posts

Thank you very much sir for your very informative sample smile I’ll try to play w/ your library later to be more famliar w/ it. Thanks again sir smile

 
Posted: 05 September 2012 06:05 PM   [ Ignore ]   [ # 42 ]   [ Rating: 0 ]
Avatar
Joined: 2009-03-19
103 posts

EDIT: Looks like this is a CHROME BUG…. :/ ... Have you seing this before ?

Hey man…

There is something wrong when using your library with AJAX… :/

Let me show you:

To manually add a product in the cart:

http://clubemagic.com/cart/addCardToCart/116

(116 is the product ID)

To add a product with AJAX:

http://www.clubemagic.com/site/card/avr/79

(Click on the orange button)

To see the cart array:

http://clubemagic.com/cart

The problem: When I add the product manually it works… When I add the product using AJAX it doesnt work… The system returns me a success message, but the product doesnt show in the cart list… :/

Can you help me ?

 
Posted: 06 September 2012 06:40 AM   [ Ignore ]   [ # 43 ]   [ Rating: 0 ]
Joined: 2010-10-26
7 posts

[Comment Removed]

 
Posted: 06 September 2012 06:46 AM   [ Ignore ]   [ # 44 ]   [ Rating: 0 ]
Joined: 2012-03-08
159 posts

Hey PoetaWD,

It looks like the problem is because the carts browser session has not been refreshed once the items have been added to the cart.

Due to the way that CodeIgniter sets its session data (Which holds the cart data), the new items added to the cart are only available once the webpage has been redirected.

Since I think its probably a good example that should be available in the demo, I will try and include examples of adding items to the cart via ajax in the next week or so.

However, if you want a pointer in the meantime, this will hopefully solve your problem.

HTML

<input type="button" value="Buy Item" class="add_item" data-url="http://www.website.com/controller_name/method_name/101"/> 

JavaScript Ajax Code

$('.add_item').click(function(event)
{
   
// Get the url of the controller and method that will insert the item to the cart.
   
var ajax_url = $(this).attr('data-url');

   
// #cart_summary_div is an example name of the div element you want to update with new cart data.
   
$('#cart_summary_div').load(ajax_url+' #cart_summary_div');

CodeIgniter Controller (In this example called ‘controller_name’)

function method_name($item_id 0)
{
   
// Load flexi cart library (if not already)
   
$this->load->library('flexi_cart');

   
// Compile item data. 
   
$cart_data = array('id' => $item_id'name' => 'Item #'.$item_id'quantity' => 1'price' => 30);

   
// Insert item to cart via flexi cart function.
   
$this->flexi_cart->insert_items($cart_data);  

   
// Redirect the ajax request to refresh the session data.
   // When called via ajax, the browser will not redirect, instead the default view/data returned
   // by the controller url will be returned to the ajax request.
   
redirect('controller_name/method_name');
   exit;

Hope that helps you out for now.

 Signature 

flexi-auth | A user authentication library for CodeIgniter.
flexi-cart | An e-commerce shopping cart library for CodeIgniter.

 
Posted: 15 September 2012 05:47 AM   [ Ignore ]   [ # 45 ]   [ Rating: 0 ]
Joined: 2012-03-08
159 posts

Hey PoetaWD,

I don’t know whether you solved your problem or not, but in any case, I’ve now updated the flexi cart demo with examples of adding items to the cart via Ajax.

You can see a working example of this at http://haseydesign.com/flexi-cart/lite_library/item_ajax_examples

The updates are available from the usual Github repo https://github.com/haseydesign/flexi-cart

 Signature 

flexi-auth | A user authentication library for CodeIgniter.
flexi-cart | An e-commerce shopping cart library for CodeIgniter.

 
Posted: 20 September 2012 05:12 AM   [ Ignore ]   [ # 46 ]   [ Rating: 0 ]
Joined: 2012-09-04
7 posts

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:

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);

   
$this->input->post('code'

is the code to be entered by the end user to apply their discount to their cart

$this->input->post('description'

is a description of the discount

$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

$this->input->post('code_value'

the amount to discount e.g., 10.00

$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:

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!

 

 
Posted: 21 September 2012 09:15 PM   [ Ignore ]   [ # 47 ]   [ Rating: 0 ]
Joined: 2012-03-08
159 posts

@JoJo17

By the looks of your code you’re doing everything right.
I just tried doing some testing myself and was puzzled why I was getting the exact problem.

What I’m betting on is that you are using the demo sql file, and due to an oversight by myself, the discounts are actually invalid - as in their expiry date has now passed.

If you are using the demo sql file, what you need to do is update the expiry dates of these discounts.
For a quick fix, try running the following sql to update all the demo discounts.

UPDATE discounts SET disc_expire_date DATE_ADD(CURDATE(), interval 1 year); 

I will update the Github repo soon with the full SQL script.

 Signature 

flexi-auth | A user authentication library for CodeIgniter.
flexi-cart | An e-commerce shopping cart library for CodeIgniter.

 
Posted: 24 September 2012 08:23 AM   [ Ignore ]   [ # 48 ]   [ Rating: 0 ]
Joined: 2012-09-04
7 posts

@haseydesign

I’m not actually using the demo sql at all, I’m integrating flexi cart into an existing site. I have checked the expiry date of my discount (originally it was 0000-00-00 as I presumed I didn’t have to set one) and have changed it to a date in the future but it still does the same so it must be a problem somewhere else. I have loaded up your demo SQL into a separate database so I can compare the differences!

 
Posted: 24 September 2012 08:54 AM   [ Ignore ]   [ # 49 ]   [ Rating: 0 ]
Joined: 2012-03-08
159 posts

Hey JoJo,

Have you tried using the example sql discount data within your own existing site?
What I mean by that, is if you insert the example discount data into your sites discount table, they should be valid and prove whether there is either a library config problem, or a database data problem.

To try this, backup/create a copy of your current discount table, and then run the following sql on the table named ‘discounts’.

TRUNCATE `discounts`;
INSERT INTO `discountsVALUES ('1''2''12''1''0''0''0''0''0''10-PERCENT''Discount Code \"10-PERCENT\" - 10% off grand total.''0''0''0.00''10.00''0''0''0''0''''''''9998''2012-05-13 00:00:00''2015-06-04 00:00:00''1''1');
INSERT INTO `discountsVALUES ('2''2''13''1''0''0''0''0''0''10-FIXED-RATE''Discount Code \"10-FIXED-RATE\" - &pound;10 off grand total.''0''0''0.00''10.00''0''0''0''0''''''''9998''2012-05-13 00:00:00''2015-06-04 00:00:00''1''1'); 

You can now test the discount codes “10-PERCENT” and “10-FIXED-RATE”.

If that doesn’t highlight the problem better, can you send me a dump of your discounts table.

 

 Signature 

flexi-auth | A user authentication library for CodeIgniter.
flexi-cart | An e-commerce shopping cart library for CodeIgniter.

 
Posted: 24 September 2012 09:04 AM   [ Ignore ]   [ # 50 ]   [ Rating: 0 ]
Joined: 2012-09-04
7 posts

@haseydesign

Your discounts work so it’s definitely me getting it wrong! Here’s my discount table:

insert into `discounts` values(‘1’,‘0’,‘8’,‘0’,‘0’,‘0’,‘0’,‘0’,‘0’,‘test1’,‘test discount code’,‘0’,‘0’,‘0.00’,‘1.00’,‘1’,‘1’,‘0’,‘0’,’‘,’‘,’‘,‘0’,‘2012-09-19 12:54:41’,‘2012-09-29 00:00:00’,‘1’,‘1’);

 
Posted: 24 September 2012 09:29 AM   [ Ignore ]   [ # 51 ]   [ Rating: 0 ]
Joined: 2012-03-08
159 posts

@JoJo

You were so close dude, you just needed to set the usage limit (disc_usage_limit).

Here’s the revised code.

INSERT INTO `discountsVALUES (108000000'test1''test discount code'000.001.001100''''''99'2012-9-19 12:54:41''2012-9-29 00:00:00'11); 

The usage limit defines how many times the discount can be used, when set to 0, the cart thinks all the discount codes have been used up.

——————————————————

I understand looking at the discount tables is a little daunting with so many columns and options.
To help out in future, I would suggest you create a separate installation of the flexi cart demo so that you can do stuff like build discounts via the provided demo and see what kind of output it does.

If you want/need to create discounts via your site, copy the code from the discount builder in the demo.
http://haseydesign.com/flexi-cart/admin_library/summary_discounts

 Signature 

flexi-auth | A user authentication library for CodeIgniter.
flexi-cart | An e-commerce shopping cart library for CodeIgniter.

 
Posted: 24 September 2012 09:35 AM   [ Ignore ]   [ # 52 ]   [ Rating: 0 ]
Joined: 2012-09-04
7 posts

@haseydesign

Thank you for your help and patience - you are correct that was the problem though I was hoping to be able to have an unlimited use which is why I wasn’t setting it!

 
Posted: 01 October 2012 05:53 AM   [ Ignore ]   [ # 53 ]   [ Rating: 0 ]
Joined: 2012-08-08
5 posts

@haseydesign

Thanks for the fix. Hopefully I’ll have the time to give it a try in the next few days.

 
Posted: 01 October 2012 09:35 PM   [ Ignore ]   [ # 54 ]   [ Rating: 0 ]
Joined: 2012-03-27
17 posts

How exactly does the shipping work? Is there some sort of integration with any major carriers(ups, usps, or fedex)?

 
Posted: 02 October 2012 08:09 AM   [ Ignore ]   [ # 55 ]   [ Rating: 0 ]
Joined: 2012-03-08
159 posts

@Procode

The shipping within flexi cart has to be manually defined - there is currently no integration with any shipping companies.

However, that said, there are still many options to allow you to customise shipping rates for many different circumstances.

Shipping rates can be based on:
+ Location / Zone.
+ Order values and weight.

Shipping options include:
+ Different pricing tiers can be defined within each shipping option.
+ Customised tax value - that can differ from the default cart value.
+ Inclusion/Exclusion from cart discounts - i.e. A 10% cart wide discount could be excluded from affecting the shipping value.

Examples of setting shipping rates via an admin backend can be seen at:
http://haseydesign.com/flexi-cart/admin_library/shipping
http://haseydesign.com/flexi-cart/admin_library/shipping_rates/1

If you, or anyone else does go down the road of trying to implement 3rd party shipping rates that can be integrated into the cart library, I’d be happy to lend a hand so the code could be included within the library for others to use. All contributors would be credited.

 Signature 

flexi-auth | A user authentication library for CodeIgniter.
flexi-cart | An e-commerce shopping cart library for CodeIgniter.

 
3 of 10
3