last day (15 days later) » 

13:52
3
A: Shopping cart class

nibraGeneral You should reconsider the naming of some methods. For example, interface IComparable { public function equals($obj); } is more clear about what it really does (comments are omitted to save space; of course, proper DocBlock comments should always be included with your code). This w...

Thanks. This is very good suggestions.
Only one question : The shopping cart is it a singleton? If so, the variable container should it not be static?
There is no reason for the cart to be a singleton (singleton is an Antipattern). On the other hand, the container property holds a reference to the cart data, so any cart provided with the same storage container will have identical data.
For example, should I call the cart this way: (new Cart())->clear()?
Why you don't use array_sum() for the isEmpty() function? And I don't understand $this->container[] = &$entry;. Why you ecrase the table?
To use the cart, you instantiate it: $myCart = new Cart;. Then you can use it's methods: $myCart->clear();. Static methods are avoided, because they hamper testing. -- array_sum is not used, because the values are not in the same array (each item is again an array within the main array).
$this->container[] = &$entry; does not erase the array, but adds a reference to the new entry.
Thanks for your help.
Sorry to insist, but I don't understand. Can you explain to me ... Why don't you have to specify the index of the array.
13:52
Read this from the PHP manual: php.net/manual/en/language.types.array.php#language.types.array.syntax.modifying‌​‌​. It'll tell you.
Thanks a lot for your help.
I corrected what I believe to be some errors in your code. Could you review to make sure I'm not the problem.
Already did so.
I do not know why, but I can not increment the quantity of an item. If I follow step by step the execution, I realize that this is the code that does not work: $entry['quantity']++; and $entry['quantity']--;.
There was another bug in getEntry(), which I corrected.
14:08
Hi nibra!
Did you try the corrected version?
First, thanks a lot. I am a new out of school technician so I do not have your experience .
I'm trying now... I come back.
ok...
Yes. It's work for the add() method but doesn't work for the remove() method.
Sorry for my poor english, I'm a french guy.
And I don't know why. When I get the quantity, it's always 0.
For removal, try
$entry['quantity'] = max(0, --$entry['quantity']);
instead of
$entry['quantity'] = max(0, $entry['quantity']--);
14:25
Wow. I do you do that!?
The unary operator '--' is position dependent. In front of the variable, the increment is done before the assignment, and after the variable the increment is done after the assignment.
14:45
I hav e some problems with the getQuanity() method. I don't know why, but a get several result duplicate.
15:12
Could you explain?
I wish I could show you my WebSite.
Hum... When I show the items in cart, a get duplicate.
I'm going to revise my code to find the error.
I think the error is inside getAll()
Thanks for your time... I will come back with some comments.
Check your `equals()` method. Does it really work as expected?
BTW: I have to leave now, being back next week.
 
2 hours later…
17:05
When you have time and if you don't mind, could you review my new code available in the post.

last day (15 days later) »