ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

flexi cart - A comprehensive shopping cart library for CodeIgniter

March 11, 2012 3:30am

Subscribe [36]
  • #31 / Aug 09, 2012 9:17am

    haseydesign

    171 posts

    Hey Valcsi,

    The PHP error warning you were receiving was a minor bug with the library.

    I have since fixed this bug and have pushed the changes to the Github repo.
    So just pull the changes from the repo and all should be working fine.

    Thanks for reporting the bug.

  • #32 / Aug 09, 2012 6:49pm

    Valcsi

    5 posts

    Thanks for the help. I’ve updated the installation, and now I get the following errors:

    A PHP Error was encountered
    Severity: Notice
    Message: Undefined property: stdClass::$cart_database
    Filename: models/flexi_cart_lite_model.php
    Line Number: 1026

    and about a 100 more with the same message but different line numbers. I also have these:

    A PHP Error was encountered
    Severity: Warning
    Message: Invalid argument supplied for foreach()
    Filename: models/flexi_cart_model.php
    Line Number: 3853

    A PHP Error was encountered
    Severity: Notice
    Message: Undefined variable: config_data
    Filename: models/flexi_cart_model.php
    Line Number: 3868

    A PHP Error was encountered
    Severity: Warning
    Message: Cannot modify header information - headers already sent by (output started at <installdir>\system\core\Exceptions.php:185)
    Filename: libraries/Session.php
    Line Number: 672

    Any idea why I get these? I appreciate your help.

    Thanks

  • #33 / Aug 09, 2012 9:57pm

    haseydesign

    171 posts

    Hey again Valcsi,
    The original warning seems to be occur in the most latest versions of PHP, which is why I originally missed it.

    The fix I put out yesterday was a late night rush job, which sadly didn’t get properly tested.
    I will try and get a proper fix out very soon.

    In the meantime, if you need to progress with development, I suggest you rollback the git update I put out last night and temporarily ignore the single warning put out until I release the fix.

  • #34 / Aug 10, 2012 6:06am

    Valcsi

    5 posts

    Ok, great thanks.

  • #35 / Aug 16, 2012 7:03am

    haseydesign

    171 posts

    Hey Valcsi,

    Sorry for the delay in patching the PHP 5.4 warning.

    If you want you can amend the very quick changes manually, or alternatively, if your still trialing with the demo, you can download the changes via the updated Github repo.

    The changes concern defining a global object to each of your controllers that load the flexi cart library. No changes were made to the actual flexi cart libraries or models!

    To manually do the change, you need to add the following code to each of your controllers JUST BEFORE you load the flexi cart library.

    $this->flexi = new stdClass;
    $this->load->library('flexi_cart');

    The user guide has been updated to reflect these changes under the heading ‘Define the global cart class’.
    http://haseydesign.com/flexi-cart/user_guide/installation

    Hopefully that gets you going again.

  • #36 / Aug 18, 2012 5:54am

    sadanandan

    1 posts

    the above fix not working and i still getting the error
    Severity: Notice
    Message: Undefined property: stdClass::$cart_database
    Filename: models/flexi_cart_lite_model.php
    Line Number: 1026.

    I tried this in different codeignitor versions, still no chance

  • #37 / Aug 18, 2012 8:33am

    haseydesign

    171 posts

    Hey Sadanandan,

    To try and regenerate the error you have stated on my local dev setup, I have just installed a brand new installation of CI 2.12 and then pulled the latest Github repo of the flexi cart library.
    My testing of this has not generated any errors.

    I think what the problem may be is that you have pulled the erroneous Github repo that was pushed out last week, and have then manually added the fix from my previous post (adding $this->flexi = new stdClass; to the controller), but without rolling back the erroneous git commit.

    If this is the case, then basically, all you need to do is pull the current Github repo, and confirm you have the latest versions of the model and library files, then within your own controllers, just ensure you have defined

    $this->flexi = new stdClass;

    before you load the library.

    Hope this helps.

  • #38 / Aug 19, 2012 11:45pm

    rei

    67 posts

    Hi sir, does this library supports product variations?

  • #39 / Aug 20, 2012 12:15am

    haseydesign

    171 posts

    Hey Rei,

    The flexi cart library does support product variations.
    You can see an example of this at http://haseydesign.com/flexi-cart/lite_library/item_form_examples

    The library is designed in a way to be compatible with custom database layouts, meaning you can structure your product and product variations tables to meet your specifications, and then just use the flexi cart library to manage the cart, orders and discount aspects of your ecommerce setup.

  • #40 / Aug 20, 2012 8:31pm

    rei

    67 posts

    Hi thanks for your reply. nwei I saw the source of the samples and the options that affects the price of a product is static. Can I make it dynamic so the prices and details will come from the database? and do u have any examples for that? Thanks in advance 😊

  • #41 / Aug 20, 2012 11:47pm

    haseydesign

    171 posts

    Hey Rei,

    I can give you a generic example of how you can get the price from the database, but this is using an example database schema that will not necessarily fit your requirements, so you will have to adjust it to your needs.

    If your not too familiar with ecommerce database schemas, spend a little time researching on Google, as different table structures can have many advantages and disadvantages to each design structure.

    Remember, all you essentially need to do is create an array of the products data, and then add that data to the cart via the ‘insert_items()’ function.
    How you get that product data is completely up to you.

    // Get the id of the product option from POST data.
    $product_option_id = $this->input->post('product_option_id');
    
    // Run your SQL query to get your product data from the database.
    $query = $this->db->select('product_table.product_id, product_table.product_name, product_options.option_name, product_options.price')
     ->from('product_table')
     ->join('product_options', 'product_table.product_id = product_options.product_id')
     ->where('product_option_id', $product_option_id)
     ->get();
    
    // Check database data was returned.
    if ($query->num_rows() == 1)
    {
     // Assign the database data to a variable.
     $product_data = $query->row_array();
    
     // Build the data array that will passed to the flexi cart 'insert_items()' function.
     $cart_data = array(
      'id' => $product_data['product_id'], 
      'name' => $product_data['product_name'].' - '.$product_data['option_name'], 
      'quantity' => 1, 
      'price' => $product_data['price']
     );
     
     // Insert the product to the cart.
     $this->flexi_cart->insert_items($cart_data);
    }
  • #42 / Aug 20, 2012 11:58pm

    rei

    67 posts

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

  • #43 / Sep 05, 2012 6:05pm

    PoetaWD

    97 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 ?

  • #44 / Sep 06, 2012 6:40am

    tical

    5 posts

    [Comment Removed]

  • #45 / Sep 06, 2012 6:46am

    haseydesign

    171 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.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases