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

[eluser]haseydesign[/eluser]
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)

Code:
// 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_g...cart_items
save_order() - http://haseydesign.com/flexi-cart/user_g...save_order
order_number() - http://haseydesign.com/flexi-cart/user_g...der_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.
#22

[eluser]koichirose[/eluser]
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_g...#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
Code:
$shipping_data = array(
'value' => 10 //example
);
$this->flexi_cart->set_shipping($shipping_data);

Tax is 21%, set with
Code:
$tax_data = array(
'rate' => 21,
'name' => 'VAT'
);
$this->flexi_cart->set_tax($tax_data);

Results:
Code:
$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:
Code:
$this->flexi_cart->item_tax_total($row_id, false, false, false); //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.
#23

[eluser]haseydesign[/eluser]
@koichirose

Thanks for the input.

Issue #1: the broken link to http://haseydesign.com/flexi-cart/user_g...#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:
Code:
$value = (! empty($this->flexi->cart_defaults['shipping'][$column])) ? $this->flexi->cart_defaults['shipping'][$column] : $data;
To:
Code:
$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.

#24

[eluser]Nassau Sky[/eluser]
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

#25

[eluser]haseydesign[/eluser]
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
Code:
$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_g...stallation

Let us know if your still struggling.
Good luck.
#26

[eluser]Nassau Sky[/eluser]
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!
#27

[eluser]haseydesign[/eluser]
Hey again Mike,
it's a little odd that the 'items via links' are not working whilst the other examples are.
The item form examples essentially work in the same manner, so the library files will be working okay.

I would suggest the best way to diagnose the problem is to start the flexi cart demo from scratch, by setting up a brand new CI installation, and then running through the flexi auth installation guide http://haseydesign.com/flexi-cart/user_g...stallation.
I know i's a little long to read but it is all pretty essential in order for the library to work.
#28

[eluser]haseydesign[/eluser]
Duplicate post
#29

[eluser]Nassau Sky[/eluser]
OK I will trudge through it again. I was praying it was something simple. I looked through the instructions and did notice I missed a part that mentioned the session and didn't notice that I missed anything else. I will have to do it again and see where it leads.

Thanks I will let you know either way how it works out.
#30

[eluser]Valcsi[/eluser]
Hi there,

Does anyone have any idea why I get this error when I view the content of the cart?

A PHP Error was encountered

Severity: Warning

Message: Creating default object from empty value

Filename: models/flexi_cart_lite_model.php

Line Number: 41

Which is this line:
Code:
$this->flexi->cart = $this->config->item('cart','flexi_cart');
I can see the items added to my cart with all the info, but I have no idea how I could fix this issue. The configs file look good, the SQL database works, the session looks OK.

Any ideas? I would really appreciate any help. Thanks




Theme © iAndrew 2016 - Forum software by © MyBB