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

[eluser]koichirose[/eluser]
Ok, thank you.

Can I help you with anything to speed this up?


I'm sorry but I'm still confused about foreign keys.

For 'disc_location_fk' and 'disc_zone_fk', I'm not sure which part of the config affects these.
I tried enabling $config['database']['locations']['table'] with one of my tables at random, but it is not used, so I'm guessing it's session based and I'd have to call '$this->flexi_cart->update_location($location_data);'.

'disc_user_acc_fk' is just for rewards? What does it do exactly?

For item_fk / group_item: the field matched is the session's item id? Some code to explain that:
Code:
var_dump($this->flexi_cart->cart_contents());
//output:
array
  'items' =>
    array
      'c4ca4238a0b923820dcc509a6f75849b' =>
        array
          'row_id' => string 'c4ca4238a0b923820dcc509a6f75849b' (length=32)
          'id' => string '122' (length=1) // <------- is this the id that will be checked and that I have to add to the 'discount_group_item' table?
          'name' => string 'Pochette' (length=8)
          'price' => string '€ 82.64' (length=9)




Lastly, please don't hate me but I guess I found another issue: I added two discounts which are exactly the same except the value discounted. So they have the same code 'TEST'.
discount code id 1 - 10%
discount code id 3 - 40%

Entering 'TEST' when applying the code produces this:
Code:
var_dump($this->flexi_cart->discount_codes());
//output:
array
  'TEST' =>
    array
      'id' => string '3' (length=1)
      'code' => string 'TEST' (length=4)
      'description' => string 'ddd' (length=3)

Savings calculations aside, as I explained in a previous message, I can use '$this->flexi_cart->total()' to check the discount code applied.
I get 10% instead of 40%. So discount_codes() reports discount #3 being applied, while the value discounted is from #1.

This won't happen in our case (and in most cases), since there can't be discounts with the same code and the same filters, but I thought it would be good to let you know.

Thanks again, have a great weekend Smile
#82

[eluser]koichirose[/eluser]
While we discuss about discounts, I'm trying to edit part of my code to use your libraries as much as possible.

These were previously false/false and now are:
Code:
$config['defaults']['configuration']['display_tax_prices'] = true; //previously, I was calculating the taxed price of each product by myself.
$config['defaults']['configuration']['price_inc_tax'] = false;

So when adding items to the cart with insert_items(), the value for price is 82.64 without VAT.

By using set_tax() and setting 'rate' to 21, I see 99.99 as price including taxes. Although, there are some rounding problems. I had them too, then I decided to use your libraries more, hoping to solve them :/

Here's what happen:
I added that item (82.64, 99.99 with VAT).
I set the quantity to 2.

Code:
echo $this->flexi_cart->item_price_total($row['row_id'], false, false, false); //199.98
echo $this->flexi_cart->item_summary_total(false, false); //199.99

Is there any way around this?
I noticed because when I started working with discounts rounding became a serious issue.

Thanks again.
#83

[eluser]GhostPepper[/eluser]
[quote author="haseydesign" date="1331451011"]Hey all,

I would like to announce the release of 'flexi cart', a comprehensive shopping cart library for CodeIgniter.[/quote]

Hi, I have been playing with your shopping cart recently. Thanks for releasing this and supporting it actively.

I have a question about this, which is found in standard_library.php in the demo:

function checkout_complete($order_number = FALSE)
{
// Note: This example uses the 'get_db_order_summary_row_array()' and 'update_db_order_summary()' function which are located in the flexi cart ADMIN library.


I've been trying to find the function get_db_order_summary_row_array() in the flexi cart libraries, models, everything, but for the life of me, I can't find it anywhere. The closest thing I found was the function get_db_order_summary_query() in the flexi cart admin library, but get_db_order_summary_row_array() is called in the demo and it seems to work. I'm missing something and I hope it's not something stupid.

Thanks again for creating and sharing this, I've been learning a lot from it.

#84

[eluser]GhostPepper[/eluser]
[quote author="GhostPepper" date="1353446320"]
I'm missing something and I hope it's not something stupid.[/quote]

Ok I see now that "query" is apparently a variable in the function names that one sets to "row_array" or "column_array" depending on the query. Didn't know you could do that.
#85

[eluser]haseydesign[/eluser]
@koichirose

Regarding your confusions with the discount foreign keys.

The 'disc_item_fk', 'disc_location_fk' and 'disc_zone_fk' columns all rely on the carts session data (As you suggested).
You seem to have worked out how they work just by what you have posted.

The 'disc_item_fk' is the item id that is saved to the cart when inserting an item.
This same id is what is matched in the 'discount_group_items' table for item group discounts.

The location and zone ids can be defined in a few different ways.
You can use the 'update_location()' function as you have stated, or you could alternatively define the location when using the 'update_cart()' function.

One important note to keep in mind, is that there are 2 different location types - a 'shipping' location, and a 'tax' location.
This allows you to define shipping rates and discounts offers via the shipping location, and taxes via the tax location.
If you need to set these 2 locations differently (Usually for tax purposes), checkout the setting data functions via the locations user guide page

You can get more information on the discount table setup at http://haseydesign.com/flexi-cart/user_g...unt_config

------------------------------------------------------------------------------------------------------------------------------------------

Regarding the issues of stacking discounts together using the same discount code, I haven't been able to replicate this via my own examples.
I will point out that when two or more discounts are valid, they are applied in the order defined via the 'disc_order_by' column in the discount table, the lower the number, the higher priority.
If you can provide a database dump of the two discount rows causing the issue, i'd be happy to look further into it.

------------------------------------------------------------------------------------------------------------------------------------------

Finally regarding the rounding issues, this was actually a large nightmare for me during development.
I managed to somewhat tighten down the inconsitencies by getting the cart to calculate values based on 4 decimals, but I could not find a 100% concrete solution or best practice of how to solve the issue.
I even tried testing other POS software systems but kept getting the same variations in rounding calculations.

This is actually something I would love to throw out there to anyone willing to offer suggestions on the best way to round up decimals when dealing with currency values containing 3 or more decimals.
These long decimals numbers are mainly caused when dealing with tax and discount percentages.

For example 2 items @ $100 each, minus a 1/3 discount (33.3333%) is $66.6666, rounded to $66.67.
So 2 discounted items now @ $66.67 equal $133.34; but if adding their values together including 4 decimals ($66.6666 x 2), it rounds to $133.33; a $0.01 difference.
Do this with more items and the difference increases.

You could suggest to just apply the 1/3 discount to the total, but the cart items need to be able to be itemised, so it needs to be calculated per item.
#86

[eluser]haseydesign[/eluser]
@GhostPepper

You seem to have sussed it out correctly yourself.
The functions (methods) you are referring to are in fact created using PHPs magic method '__call()' to overload the method (e.g. get_db_order_summary_row_array() over get_db_order_summary_query()).

You can find this defined within the file 'libraries/flexi_cart_lite.php' @ line 38.

You can read up further via the user guide @ http://haseydesign.com/flexi-cart/user_g...ery_syntax
#87

[eluser]koichirose[/eluser]
Hi haseydesign,

Here's the dump for those discounts:
Code:
insert  into `mkt_discount`(`discount_id`,`discount_type_id_fk`,`discount_method_id_fk`,`discount_tax_method_id_fk`,`user_id_fk`,`TEMP_product_version_id_fk`,`discount_group_id_fk`,`country_id_fk`,`zone_id_fk`,`discount_code`,`description`,`quantity_required`,`quantity_discounted`,`value_required`,`value_discounted`,`is_recursive`,`is_non_combinable_discount`,`void_reward_points`,`force_ship_discount`,`custom_status_1`,`custom_status_2`,`custom_status_3`,`usage_limit`,`insert_time`,`update_time`,`start_date`,`end_date`,`status`,`order_by`) values (1,2,7,1,0,0,0,0,0,'TEST','iiii',NULL,NULL,NULL,10.00,NULL,NULL,NULL,NULL,'0','0','0',65531,'2012-11-15 12:49:40','2012-11-15 18:55:29','2012-11-14 12:49:40','2012-11-26 12:49:40',1,100),(3,2,7,1,0,0,0,0,0,'TEST','ddd',NULL,NULL,NULL,40.00,NULL,NULL,NULL,NULL,'0','0','0',65535,'2012-11-15 12:49:40','2012-11-15 18:55:29','2012-11-14 12:49:40','2012-11-26 12:49:40',1,100);

I changed the names of some columns so I don't think you'll be able to import as is.

Entering TEST as a coupon code applies a 10% discount (discount id 1), but var_dump($this->flexi_cart->discount_codes()); shows this:
Code:
array
  'TEST' =>
    array
      'id' => string '3' (length=1)
      'code' => string 'TEST' (length=4)
      'description' => string 'ddd' (length=3)

Thank you
#88

[eluser]haseydesign[/eluser]
@koichirose

Thanks for the SQL dump, it helped me regenerate your example.

Technically the settings for the discount are partially at fault as the 'disc_order_by' column is meant to deal with this sort of issue, by defining an order priority that discounts are applied.
In you example sql dump, the order by values where both the same so the cart didn't know which to prioritise.

However, I've patched the library to help prevent this happening.
The patch is available via the usual Github repo.

Thanks again
Rob

#89

[eluser]GhostPepper[/eluser]
[quote author="haseydesign" date="1353497556"]You can find this defined within the file 'libraries/flexi_cart_lite.php' @ line 38.[/quote]

Thanks for this. It helped my understanding of magic methods.

I have a quick question about your tax calculation. On your online demo, I select "Example #102 : Add multiple items at once with 1 link" then go to view cart. The Item Summary Total calculates out to 74.45. The tax "VAT @20%" calculates out to 13.07... but 20% of 74.45 is 14.89. Am I missing something here?

Thanks again!
#90

[eluser]haseydesign[/eluser]
Hey GhostPepper,

I think you've made a small error in your calculations.
Your example of removing 20% from 74.45 returning 14.89 (74.45 * 0.2) is not how you calculate tax.
For example, 100 + 20% = 120, but 120 * 0.2 = 24 rather than 20.

Another point that would cause you further error, is that the price for items #102 is 74.45 plus the shipping cost which also in this example includes tax. So you would need to calculate 20% of (74.45 + 3.95), which equals 13.07.

Have a quick read of http://www.simetric.co.uk/si_deduct_tax.htm to get a little more detail.




Theme © iAndrew 2016 - Forum software by © MyBB