32 thoughts on “Build A Shopping Cart with PHP: Adding items (7/15)

  1. Great series! It's understandable that everyone needs something else i personally thought it will be done from the ground up on your own MVC instead of ready-mades. Anyway very well made tuts!

  2. If anyone is facing a situation where your items quantity is not increasing make sure to check the functions: add, update and has. I forgot to pass the arguement in has and hence it wasn't updating. Good luck.

  3. Hi Alex or others, I need some help below this error
    Fatal error: Cannot declare class CartSupportStoragesSessionStorage, because the name is already in use in /Applications/XAMPP/xamppfiles/htdocs/cart/app/Support/Storage/SessionStorage.php on line 8

    here is the code

    namespace CartSupportStorages;

    use Countable;
    use CartSupportStorageContractsStorageInterface;

    class SessionStorage implements StorageInterface, Countable
    protected $bucket;

    public function __construct($bucket = 'default')
    if(!isset($_SESSION[$bucket])) {
    $_SESSION[$bucket] = [];

    $this->bucket = $bucket;

    public function set($index, $value)
    $_SESSION[$this->bucket][$index] = $value;

    public function get($index)
    if (!$this->exists($index)) {
    return null;

    return $_SESSION[$this->bucket][$index];

    public function exists($index)
    return isset($_SESSION[$this->bucket][$index]);

    public function all()
    return $_SESSION[$this->bucket];

    public function unset($index)
    if ($this->exists($index)) {

    public function clear()

    public function count()
    return count($this->all());

  4. Catchable fatal error: Argument 1 passed to CartBasketBasket::get() must be an instance of CartModelsProduct, integer given, called in C:xampphtdocscartappBasketBasket.php on line 86 and defined in C:xampphtdocscartappBasketBasket.php on line 62

    Someone please help me 🙁

  5. Hi, I have this problem
    Notice: Undefined index: product_id in C:laragonwwwcartappBasketBasket.php on line 67

    Warning: Invalid argument supplied for foreach() in C:laragonwwwcartappBasketBasket.php on line 71

    please help me

  6. Hmmm, how is it that Alex gets the quantity when outputs {{ basket.all | json_encode }} at 41:18 if there is no field in the products table called "quantity" and neither a public property in the Product model?

  7. I am getting this error…. please somebody help me….
    Undefined index: default in C:xampphtdocsCartappSupportStorageSessionStorage.php on line 44
    this error is from all() method in SessionStorage class

  8. If anybody has a return of error 500, so an internal server error, try changing the function 'unset($index)' in basket, to something like unsetItem($index), I was stuck on this for days. It was conflicting with the inbuilt unset function.

  9. Hi! I'm getting this error

    Fatal error: Cannot declare class Basket because the name is already in use in C:xampphtdocsTutorialsShoppingCartCodeCourseappbasketBasket.php on line 9

    I have no idea why this is happening :S

  10. If i try and use the itemCount function on the navigation.twig partial -> {{basket.itemCount}}, my whole site just dies and says "This site can't be reached"
    "The connection was reset"

    Please help 🙁

  11. I follow all your videos and they are great! However, I had just finished the Slim 3 authentication series and started this one and I have a question: is there any specific reason why you are specifying the Class names into the function arguments as in the auth series we did not do this? Thx!

  12. Im getting a unset error..
    Parse error: syntax error, unexpected 'unset' (T_UNSET), expecting identifier (T_STRING) in PATHrootcartappSupportStorageSessionStorage.php on line 45

Leave a Reply

Your email address will not be published. Required fields are marked *