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]
  • #46 / Sep 15, 2012 5:47am

    haseydesign

    171 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

  • #47 / Sep 20, 2012 5:12am

    JoJo17

    11 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!

     

  • #48 / Sep 21, 2012 9:15pm

    haseydesign

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

  • #49 / Sep 24, 2012 8:23am

    JoJo17

    11 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!

  • #50 / Sep 24, 2012 8:54am

    haseydesign

    171 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 `discounts` VALUES ('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 `discounts` VALUES ('2', '2', '13', '1', '0', '0', '0', '0', '0', '10-FIXED-RATE', 'Discount Code \"10-FIXED-RATE\" - £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.

     

  • #51 / Sep 24, 2012 9:04am

    JoJo17

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

  • #52 / Sep 24, 2012 9:29am

    haseydesign

    171 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 `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, '', '', '', 99, '2012-9-19 12:54:41', '2012-9-29 00:00:00', 1, 1);

    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

  • #53 / Sep 24, 2012 9:35am

    JoJo17

    11 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!

  • #54 / Oct 01, 2012 5:53am

    Valcsi

    5 posts

    @haseydesign

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

  • #55 / Oct 01, 2012 9:35pm

    Procode

    13 posts

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

  • #56 / Oct 02, 2012 8:09am

    haseydesign

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

  • #57 / Oct 20, 2012 7:15am

    georgegijo

    3 posts

    Flexi cart is a great library of shopping cart functions. I am trying to use it for an ecommerce project, but find it lacks adding new items. What I am going to do is to use the demo_items table itself to create new items and proceed from there. Please let me know the associated tables to be populated along with adding a new product item.

    If possible can you please add sample code for adding a product item.

    Thanks

  • #58 / Oct 21, 2012 11:42pm

    haseydesign

    171 posts

    @georgegijo

    The flexi-cart library deliberately doesn’t come with any product item management functions. The reason being is that e-commerce sites can have vastly different database
    designs from one site to another.

    So by omitting the functionality from the library, it allows the developer to plug the library into the setup they want, rather than forcing them to use a design that is potentially unsuitable to their needs.

    To get a better understanding of some of the most common database designs for product tables on e-commerce sites, checkout this very good summary posted on Stackoverlow @ http://stackoverflow.com/a/695860/99106

    As the most basic of examples, the flexi-cart demo includes a single table named ‘demo_items’. If you need an example of inserting records to this table it could be done as simply as:

    $sql_insert = array(
        'item_cat_fk' => 3,
        'item_name' => 'My Example Item',
        'item_price' => 29.99,
        'item_weight' => 9
    );
    $this->db->insert('demo_items', $sql_insert);

    However, if you’re unfamiliar with the native functions within CI (As used above), then I suggest you spend a couple of hours reading through the CI documentation just to give yourself an idea of what CodeIgniter can do. Once you know what it can do, then you can hunt down how to actually do it when you need to apply it.

    http://ellislab.com/codeigniter/user-guide/database/active_record.html

     

  • #59 / Oct 25, 2012 10:17pm

    AlwynW

    3 posts

    While I was looking forward to using your library I can’t make it work. I installed all the files correctly (demo files running fine as well) and just want to add an item to the cart and that’s where it goes wrong.
    I’m using this code in my controller:

    $cart_data = array(
                    'id' => $item_id,
                    'name' => $name,
                    'quantity' => $quantity,
                    'price' => $price
                );
    
           $this->flexi_cart->insert_items($cart_data);

    And this is the error:

    Message: Undefined index: internal_price
    Filename: models/flexi_cart_model.php
    Line Number: 771

    Which is a variable that according to the documentation is calculated automatically.
    This is an exact copy of the code from the demo. What am I doing wrong?

  • #60 / Oct 26, 2012 5:08am

    haseydesign

    171 posts

    @AlwynW

    I know this will be a frustrating answer for you, but from what I can see, this is (Most likely) going to be a configuration problem that you are having. A problem that is going to be very hard for me to pinpoint without seeing your library setup.

    The insert_items() code you have posted is fine - this is not where your problem lies.

    What I do when in your situation is to reverse engineer the demo (Which you suggest IS working for you).
    Take one of the working examples from the demo, and piece by piece, start changing the code to match the codebase you’re aiming to create. Keep testing everytime you remove or add code until something causes the error you are seeing - then you will have found your problem.

    If your still having trouble you could send me your current setup zipped and I’ll try and have a look at it when I get time.

    Good luck.

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

ExpressionEngine News!

#eecms, #events, #releases