EllisLab text mark
Advanced Search
1 of 10
1
   
flexi cart - A comprehensive shopping cart library for CodeIgniter
Posted: 15 May 2012 09:30 AM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Joined: 2009-05-11
52 posts

I don’t really understand how to offer a seamless experience for both logged users and guests.
Examples:

- A guest puts items in the cart. The guest logs in -> items are saved to the db in addition to the session. (I guess I could manage this in the login function, calling save_cart_data() right there, or is there something better?)
- A guest wants to view his cart -> load items from the session. (this works great)
- A logged-in user wants to view his cart -> load items from the db (this I don’t understand: saved cart data on the db doesn’t include some fields. This is the same product saved in the session and saved on db and unserialized:

//session
array
      
'row_id' => string 'd3d9446802a44259755d38e6d163e820' (length=32)
      
'id' => string '10' (length=2)
      
'name' => string 'shoes' (length=5)
      
'quantity' => string '1' (length=1)
      
'price' => string '€99.99' (length=11)
      
'stock_quantity' => string '10' (length=2)
      
'internal_price' => float 99.99
      
'weight' => string '0g' (length=2)
      
'tax_rate' => string '20%' (length=3)
      
'shipping_rate' => boolean false
      
'separate_shipping' => boolean false
      
'reward_points' => string '1,000' (length=5)
      
'status_message' => 
        array
          empty
      
'tax' => string '€16.67' (length=11)
      
'non_discount_quantity' => string '1' (length=1)
      
'discount_quantity' => string '0' (length=1)
      
'price_total' => string '€99.99' (length=11)
      
'discount_price' => string '€99.99' (length=11)
      
'discount_price_total' => string '€99.99' (length=11)
      
'discount_description' => boolean false
      
'tax_total' => string '€16.67' (length=11)
      
'weight_total' => string '0g' (length=2)
      
'reward_points_total' => string '1,000' (length=5)

//db
array
      
'd3d9446802a44259755d38e6d163e820' => 
        array
          
'row_id' => string 'd3d9446802a44259755d38e6d163e820' (length=32)
          
'id' => string '10' (length=2)
          
'name' => string 'shoes' (length=5)
          
'quantity' => float 1
          
'price' => float 99.99
          
'stock_quantity' => string '10' (length=2)
          
'internal_price' => float 99.99
          
'weight' => int 0
          
'tax_rate' => boolean false
          
'shipping_rate' => boolean false
          
'separate_shipping' => boolean false
          
'reward_points' => boolean false
          
'status_message' => 
            array
              empty
          
'tax' => float 16.665 

So a bunch of fields are missing?

Thanks smile

 
Posted: 15 May 2012 10:05 AM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Joined: 2012-03-08
159 posts

Hey koichirose,

To give you some idea of whats happening there, session data and database data purposely contain different data.
The session needs to contain much more data that is used internally by the library to help work out whats happening with the live data within the cart, whilst the database data is a primarily a readable summary of order data.

It is possible to save an order to the database, then close your browser (so the session data is deleted) and then reload the saved database data back into the users session.
When reloading the database data back into the session, the library internally repopulates all of the ‘missing’ fields - however, you must use the libraries functions to do this.

To see an example of this feature in action, try out the following page : http://haseydesign.com/flexi-cart/standard_library/load_save_cart_data
Note that currently, only the third date list in ‘‘Load Saved Cart Data’ is working (A cockup by me trying to fudge the serialized strings using SQL rather than the library - this error should not happen when using the library and affects this demo only).
If you add some items to your cart, then save the cart via this page, then load another cart, you will be able to see the feature in action.

The above page allows a user to save their cart session to the database and then reload it again from the database into their current browser session.
This demo page and its functionality can be viewed via the ‘load_save_cart_data’, ‘save_cart_data’ and ‘load_cart_data’ methods in the ‘standard_library.php’ controller.
The user guide page http://haseydesign.com/flexi-cart/user_guide/database_cart_data_admin details the functions required for this feature.

If all is still not clear, let me know.
Cheers,
Rob

 Signature 

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

 
Posted: 15 May 2012 01:02 PM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Joined: 2009-05-11
52 posts

Thank you, I’ll look into it tomorrow morning!

For now I’m trying to set the language, so I created another folder (inside application/language), pasted flexi_cart_lang.php and translated everything.
I’m having trouble loading the correct lang, since I’m setting a codeigniter variable in a hook - i.e. I do:

$CI =& get_instance();
$CI->settings->ci_language 'italian'

Then I tried editing flexi_cart_lite_model.php, since apparently that’s where the language is loaded:

$this->lang->load('flexi_cart'$this->settings->ci_language); 

Inside __construct though I can’t use $this, nor get_instance, so I don’t know how to access that variable.
I see there’s a &__get() function in that model, but I don’t understand if it could help me.

Thank you again!

 
Posted: 15 May 2012 08:28 PM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Joined: 2011-03-16
67 posts
haseydesign - 03 April 2012 09:56 PM

@Ryan

1) flexi cart doesn’t currently have any payment gateways built into the library.
I have personally integrated flexi cart with WorldPay and have had no problems.
It’s just a case of reading through the payment gateways api documentation, and then using flexi carts functions to pass the required data.

If and when I get the time, i’ll try and look into creating some demos for popular gateways like PayPal.
If you end up implementing it with a gateway, i’d be interested if you were happy to share the code.

I just finished a small shopping site (unfortunately without your cart) using Stripe as a payment processor.  it was very easy to integrate.  And you can get an account without giving them financial data to let you test things out with charging, customers, coupons, subscriptions, etc.

/ not an employee of Stripe
// Not striped either.

smile

 
Posted: 19 May 2012 02:39 AM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Joined: 2012-03-08
159 posts

@koichirose

Sorry for the delay in reply - busy week.

Firstly, what you have done regarding copying the ‘english/flexi_cart_lang.php’ file to ‘italian/flexi_cart_lang.php’ and translating the file is correct.
As for the hook, I’m not too familiar with using hooks in CodeIgniter, and from a quick attempt myself, I see your problem.

However, do you really need to set the language via a hook?
Typically, if you want to set a specific language you can define the language via CodeIgniters config.php file, by setting

$config['language''italian'

If you need a more variable solution, so that for example the language could be changed by a user on the site, you can define the language to use via the __construct() of the controller,  just before the flexi cart library is loaded.

$this->lang->load('flexi_cart''italian');
  
$this->load->library('flexi_cart'); 

Would this be suitable?
Would you mind sharing the translated Italian language file with the library? I’ll be sure to credit your name to the file.

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

@Patrick Spence
I’ve seen Stripe being mentioned about a fair bit.
As you say, the problem with developing for alot of payment processors is needing to create a financial account, but since you say Stripe doesn’t require this, i’ll have to give it a look when I get some time.

 Signature 

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

 
Posted: 19 May 2012 11:39 AM   [ Ignore ]   [ # 16 ]   [ Rating: 0 ]
Joined: 2011-03-16
67 posts

@Patrick Spence
I’ve seen Stripe being mentioned about a fair bit.
As you say, the problem with developing for alot of payment processors is needing to create a financial account, but since you say Stripe doesn’t require this, i’ll have to give it a look when I get some time.

I threw up the code I am using to talk to stripe here: https://github.com/ariven/stripe-integration-as-models

They really were easy to work with, only took me a couple days to type it all in.  I have it active on one ecommerce site now, and am in the middle of integrating in another.  Its taking me longer to create the forms and do program logic on the site rewrite than it does to integrate the charging.

One advantage to stripe is that you can use their javascript method to grab a card token, so the customers credit card doesn’t have to hit your server… so less issues with PCI-DSS and hacked sites.

Though you CAN grab the card and get a token via php.

 
Posted: 21 May 2012 04:40 AM   [ Ignore ]   [ # 17 ]   [ Rating: 0 ]
Joined: 2009-05-11
52 posts

Sure, here it is: http://pastie.org/3943648

I’m not a professional translator though.
We’re planning to translate this to russian, too. I’ll send you that one when it’s ready smile

The language tip is working. I thought that once loaded in the model I couldn’t overwrite the language setting.

Thank you once again!

 
Posted: 22 May 2012 09:10 AM   [ Ignore ]   [ # 18 ]   [ Rating: 0 ]
Joined: 2012-03-08
159 posts

I have just released an update to the flexi cart library, which is available to download from the Github repo at https://github.com/haseydesign/flexi-cart.

The update includes some improvements to how status and error messages are returned by some of the internal functions within the library.
As well as specifying whether a message should only be displayed to either public or admin users, there is now a config option to prevent specific messages from being set at all.

Additionally, there are now additional language files that the libraries status and error messages can be displayed as.
The languages are Italian (Thanks @koichirose for this), French, German and Spanish.

For further information on these changes, please refer to the change log and user guide.

 Signature 

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

 
Posted: 28 May 2012 01:07 PM   [ Ignore ]   [ # 19 ]   [ Rating: 0 ]
Joined: 2009-05-11
52 posts

Hey, thanks for the credit.

I just saw that the save_order function saves on two db tables (order_summary and order_details).
I need to introduce a third table in between, ex.:
order_summary has an order_id (autoincrement) = 23
order_store has an order_summary_id = 23 and an order_store_id (autoincrement) = 54
order_details has an order_store_id = 54 and an order_details_id (autoincrement) = 187

This is necessary for a multi-store e-commerce site.

Can it be done somehow with flexi-cart?

Thanks

 
Posted: 29 May 2012 06:37 AM   [ Ignore ]   [ # 20 ]   [ Rating: 0 ]
Joined: 2012-03-08
159 posts

Hey again koichirose,
What I would do in the scenario you have outlined is as follows.

1. Before you call the save_order() function, insert an empty record into your custom order_store table using CI’s standard SQL functions.
2. Get the insert_id for the new table row.
3. Call the save_order() function and pass the insert_id to the save_order() functions $custom_item_data parameter - this will save the id of your order_store table to each item row in the order_details table.
4. When the save_order() function has saved the data, use the order_number() function to get the unique id (The order number) of the order_summary table.
5. Update your custom order_store table with the order_number value.

This should mean that your custom order_store table now has the unique id of the order_summary table, and the multiple newly added rows in the order_details will have the unique id of your order_store table.

Here’s a rough example (Not tested)

// Insert record to custom order_store table.
// Insert whatever data you need, the aim is just to insert a record and get the id of the new row. 
$order_store_data = array(...);
$this->db->insert('order_store'$order_store_data);
$order_store_id $this->db->insert_id();

// Now we need to add the insert_id to each item row within the order_details table.
// To associate the insert_id with each item, we need to loop through the items that are in the cart and create an array.
// Use the cart_items() function to return an array of all cart items that we can then loop through.
$custom_item_data = array();
foreach(
$this->flexi_cart_admin->cart_items() as $row_id => $item)
{
 $custom_item_data[$row_id][
'order_store_id'$order_store_id;
}

// Now use the save_order() function with the $custom_item_data array. 
$this->flexi_cart_admin->save_order(false$custom_item_data);

// Get the order number of the newly added order (i.e. The unique id of the order_summary table)
$order_number $this->flexi_cart_admin->order_number();

// Update your custom order_store table with the unique id of the order_summary table.
$sql_update_data = array('order_summary_id' => $order_number);
$sql_where = array('order_store_id' => $insert_id);
$this->db->update('order_store'$sql_update_data$sql_where); 

Function reference:
cart_items() - http://haseydesign.com/flexi-cart/user_guide/cart_item_session_data#cart_items
save_order() - http://haseydesign.com/flexi-cart/user_guide/order_set_data#save_order
order_number() - http://haseydesign.com/flexi-cart/user_guide/cart_config_session_data#order_number

—-

Without knowing your full scenario, I will point out that it may be better/easier to just associate the order_store_id with the single row in the order_summary table, rather than for each order_details row.
Each row within the order_details table could then get the order_store it is assoicated to by using the parent order_summary table.

But hey, thats just a suggestion, it may not be suitable for what you’re doing.

 Signature 

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

 
Posted: 29 May 2012 11:19 AM   [ Ignore ]   [ # 21 ]   [ Rating: 0 ]
Joined: 2009-05-11
52 posts

Thank you, I think I’ll go with this solution.
I need the third table since I need to save split data for each store.

I wanted to report a couple of what may be bugs:
1. In your doc pages the anchors don’t seem to work (ex. this link is not taking me to the tax_total section: http://haseydesign.com/flexi-cart/user_guide/cart_summary_session_data#tax_total )

2. It seems that the shipping is taxed even though $config[‘defaults’][‘shipping’][‘tax_rate’] = 0;
Example:
I’m adding one item to my cart (€22), quantity: 2 (€44), shipping is €10, set with

$shipping_data = array(
 
'value' => 10 //example
);
$this->flexi_cart->set_shipping($shipping_data); 

Tax is 21%, set with

$tax_data = array(
 
'rate' => 21,
 
'name' => 'VAT'
);
$this->flexi_cart->set_tax($tax_data); 

Results:

$this->flexi_cart->item_summary_total(); // 44
$this->flexi_cart->shipping_total(); // 10
$this->flexi_cart->tax_name()." @ ".$this->flexi_cart->tax_rate(); //VAT @ 21%
$this->flexi_cart->tax_total(); //11.34, calculated on €54
$this->flexi_cart->total(); //65.34 (54+11.34) 

Results in a foreach cart items:

$this->flexi_cart->item_tax_total($row_idfalsefalsefalse); //9.24, calculated on €44, without shipping 

I’m guessing the 11.34 is wrong - tax has to be calculated on products without shipping.
Or viceversa. Actually, maybe 11.34 is correct and 9.24 is not.

How can I set this? I am not (yet) using a shipping db table, but even then I’ll still set shipping rate as shown above.

Thank you once again.

 
Posted: 31 May 2012 09:18 AM   [ Ignore ]   [ # 22 ]   [ Rating: 0 ]
Joined: 2012-03-08
159 posts

@koichirose

Thanks for the input.

Issue #1: the broken link to http://haseydesign.com/flexi-cart/user_guide/cart_summary_session_data#tax_total
This seems to work fine for me, perhaps your browser is jumping to the last position you were viewing on the page before a page refresh? - Or is there something I’m misunderstanding?

Issue #2: Shipping tax rate set as ‘0’ via the config file is being ignored.
This was definitely a bug, the value ‘0’ was being treated as FALSE, and so was being ignored.

I have fixed this problem and made the change to the Github repo.
If you’d prefer to just change the errornous line, its located on line 2060 within flexi_cart_model.php.

Change the following line from:

$value = (! empty($this->flexi->cart_defaults['shipping'][$column])) ? $this->flexi->cart_defaults['shipping'][$column] $data

To:

$value = (! empty($this->flexi->cart_defaults['shipping'][$column]) || $this->non_negative($this->flexi->cart_defaults['shipping'][$column])) ? 
  
$this->flexi->cart_defaults['shipping'][$column] $data

I haven’t had a chance to properly test this yet, so if things are still weird, let me know.

 Signature 

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

 
Posted: 16 July 2012 03:29 PM   [ Ignore ]   [ # 23 ]   [ Rating: 0 ]
Joined: 2012-07-16
3 posts

Hi,


Flexi-cart library looks very nice but after I got it installed, everything is looking good except no items can be added to the cart.  No errors either, it just returns to the view after I click on any of the examples such as Example 101 , Example 102 etc.

Any ideas what maybe I’m missing?

Thanks,
Mike

 
Posted: 17 July 2012 07:11 AM   [ Ignore ]   [ # 24 ]   [ Rating: 0 ]
Joined: 2012-03-08
159 posts

Hi Mike,

Since you seem to suggest that the installation is generally working okay - i.e. there being no errors - I would presume the problem to be with either CI’s sessions or the database setup.

I will take a guess that maybe the ‘sess_use_database’ setting in CI’s config/config.php file is not set as ‘true’.
It MUST be set as

$config['sess_use_database'TRUE

If that doesn’t help and you haven’t done so already, install a brand new installation of CI and then run through the flexi cart step by step installation guide http://haseydesign.com/flexi-cart/user_guide/installation

Let us know if your still struggling.
Good luck.

 

 Signature 

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

 
Posted: 17 July 2012 10:13 PM   [ Ignore ]   [ # 25 ]   [ Rating: 0 ]
Joined: 2012-07-16
3 posts

99% there. Like you said, changing from false to true worked for most items.

$config[‘sess_use_database’] = TRUE;  // <——Great

but it’s odd that none of the items via links work (the 100 series) am I missing something else that you can think of. 

Thanks!

 
1 of 10
1