Laravel Shopping Cart


I have searched at internet and found not much more Shopping cart class library for Laravel framework which will be very easy to manage even for a new developer.
Then i have decided to develop a very simple shopping cart library which will manage the shopping cart of my e-commerce web site.

Here it is:

LaravelShoppingCart

A Simple Session Based Database Driven Shopping Cart Library For Laravel.

It’s Really Simple & Easy To Manage Your Shopping Cart Item At Laravel

Installation

Download The Class Library and put it to app/Http/Libraries folder

Now Load the Cart Class To your base controller

use App\Http\Libraries\Cart;

Now you’re ready to start using the shoppingcart in your application.

Usage

Add the table to your database,

database/order_data_temps.sql

The shopping cart gives you the following methods to use:

You Need to Create an Object Of the Cart Class Then

$cart = new \App\Http\Libraries\Cart();

$cart->setTable()

If you want to set your rename table instead of default then just pass the name to setTable() method

$cart->setTable('my_custom_order_table');
Note: The Table must have the columns that are exist in default table.

$cart->insert()

Adding an item to the cart is really simple, you just use the insert() method, which accepts a variety of parameters.

In its most basic form you can specify the id, name, quantity, price of the product you’d like to add to the cart.

$data = array(
    'product_id' => 4,
    'quantity' => 5,
    'price' => 258,
    'name' => 'child dress'
);  
$cart->insert($data);

As an optional fifth parameter you can pass others items information as options, so you can add multiple items with the same id, but with a different size or color etc.

$data = array(
    'product_id' => 4,
    'quantity' => 5,
    'price' => 258,
    'name' => 'child dress',
    'options' => ['size'=> 'L', 'type' => 'Silk', 'Manufacturer' => 'Cat\'s Eye']
);  
$cart->insert($data);

$cart->update()

To update an item in the cart, you’ll first need the rowId of the item.
Next you can use the update() method to update it.

If you want to update any item then pass it to array and it will replace, you’ll pass the update method the rowId and the new info of product:

$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';
$data = array(  
    'quantity' => 5,    
    'name' => 'child dress',
    'options' => ['size'=> 'L', 'type' => 'Silk', 'Manufacturer' => 'Cat\'s Eye']   
);  
$cart->update($rowId, $data);

$cart->getItems()

YYou just class the getItems() method to get all cart items

$cart->getItems();

$cart->removeItem()

To remove an item from the cart, you’ll again need the rowId. This rowId you simply pass to the removeItem() method and it will remove the item from the cart.

$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';

$cart->removeItem($rowId);

$cart->removeAllItems()

If you want to completely remove the content of a cart, you can call the removeAllItems method on the cart. This will remove all CartItems from the cart.

$cart->removeAllItems();

$cart->total()

The total() method can be used to get the calculated total of all items in the cart, based on there price and quantity.

$cart->total();

$cart->total_items()

If you want to know how many items there are in your cart, you can use the total_items() method. This method will return the total number of items in the cart. So if you’ve added 2 Pens and 1 umbrella, it will return 3 items.

$cart->total_items()

Download the Code From My GitHub Account:
null

Advertisements

Symfony 3, Add A New Column To Database Table Using Doctrine Command


Modify you metadata file with new column name that you are going to add/modify. For example i have a user table metadata file and want to add a phone column. The metadata file is in yml format. Metadata files are found under the following path


src/AppBundle/Resources/config/doctrine

lets open the file that you want to modify and add the following lines:


phone:
    type: string
    nullable: true
    length: 255
    options:
        fixed: false    

Now Run the following doctrine command to update your Entity class based on the changes at your metadata file. Here i am updating only my Users Entity Class.



php bin/console doctrine:generate:entities AppBundle:Users


Now run the following doctrine command to update your database table with the modification you have done yet.



php bin/console doctrine:schema:update --force


Symfony 3 Generate Entity Class From an Existing database using Doctrine Command


Generate Metadata files using Doctrine command, Metadata files describe the entity class to generate based on database tables. You can generate xml or yml format.


php bin/console doctrine:mapping:import --force AppBundle xml

OR

php bin/console doctrine:mapping:import --force AppBundle yml

You can see your metadata files are created under the following path based on the database tables you have in your database.


src/AppBundle/Resources/config/doctrine

Once Metadata files are generated, now you can create your entity classes using the following Doctrine command. Following two command will generate the Entity classes for each table including annotation, setter and getter methods.


php bin/console doctrine:mapping:convert annotation ./src

php bin/console doctrine:generate:entities AppBundle

Now you can see the created Entity files under following directory.


src/AppBundle/Entity

Laravel 5.2 application download using composer & enable laravel user authentication.


The installation technique is only for Windows Machine with Xampp/Wamp Server.

1. Download & Install Composer in your local machine. Click here to download

2. Now Go to your server root directory using command prompt. (ie. C:\wamp\www)

3. run the following command


composer create-project laravel/laravel laravel

4. Your Laravel Project is now ready to browse. By Default laravel project root directory is public folder. You can Change server.php filename to index.php file thus the main project directory can be browse.

5. Lets Install Authentication Scaffolding Files. Go to your project root folder using command prompt (ie. C:\wamp\www\laravel) and run the following code


php artisan make:auth

6. Now This is the time to Create your database. You can create your database before too. create a database name as like “laravel32”

7. Connect your created database with your laravel project. You Can use .env file at project root folder to manage your database connection. lets open the file .env in your text editor and change the database connection info like below:


DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel32
DB_USERNAME=root
DB_PASSWORD=null


8. Now You have to run the migrate command to generate user table for managing authentication. This code will create user table and others dependencies tables.


php artisan migrate

9. One Task already left. Create a .htaccess file to the project root directory and copy & paste the below code in htaccess file.


<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /laravel/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

10. That is it. Do a registration and login with the registered user.

11. Browse & Enjoy

Here is a sample code developed using laravel 5.2 with authentication, user management system enable. You can download from my github account.

Github link: https://github.com/ziyed/laravel-5.2

CakePHP 3 project creation process using composer technique, very easy and faster.


The installation technique is only for Windows Machine with Xampp/Wamp Server.

1. Download & Install Composer in your local machine. Click here to download

2.  Now Go to your server root directory using command prompt. (ie. C:\wamp\www)

3. Run the Following code Now


composer self-update && composer create-project --prefer-dist cakephp/app bookmarker

4. Well Done!! You just setup a fresh CakePHP latest version Application using composer. Now modify your application based on your desire requirement.

5. Now You Need to Run the Code. Go to Your project directory and run the following code


bin\cake server

6. You will get a url like (http://localhost:8765/). Copy & browse.

cakephp3

7. Setup you database connection and use the cake console for rapid development.

Here is the sample CakePHP 3 Project for you in case you have a mistake. Download and Enjoy.

Github Link: https://github.com/ziyed/CakePHP3

Useful Git Commands listed with its uses briefly


Here is some useful commands to manage your development using git


git init (Initialize your git project directory)
git status (Check current status)
git add filename (Add a single file created or modified)
git add . (Add all new file created or modified)
git add *.html (Only add html files that is newly created or modified)
git commit -m “first commit” (Commit to repository after add with a comment)
git push origin master (Push all files to origin master)
git log (Check log)
touch gitignore (Create a .gitingore file, enter a file name will be ignored while adding/updating)
git branch MyBranch (Create Own Branch)
git checkout MyBranch (Select a branch for work/change)
git merge MyBranch (Merge my new branch with master branch)
git merge master (merge master with branches)
git stash (save the new file created yet for future commit)
git stash apply (Commit the stash file/files)
git remote (view remote repositories)
git clone repository-url (Checkout the remote git project)
git remote -v (See original source url)
git fetch origin (Will download but not merge)
git pull origin ( will download and merge altogether)