1. Go to this page and download the library: Download tefo/cart library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tefo / cart example snippets
use Tefo\Cart\HasCart;
use Tefo\Cart\InteractsWithCard;
class Product extends Model implements HasCart
{
use InteractsWithCard;
// ...
}
$itemId = '92e1b081-17b9-4f7a-8f91-91da9dbcd6ca'; // its uuid
Cart::update($itemId, $updatedProduct); // Will update the id, name and price
Cart::update($itemId, ['name' => 'Product 1']); // Will update the name
$itemId = '92e1b081-17b9-4f7a-8f91-91da9dbcd6ca';
Cart::updateQuantity($itemId, 2); // Will update the quantity
Cart::session('shopping')->addItem(['id' => 1, 'name' => 'Product 1', 'price' => 9.99], ['quantity' => 1]);
// Get the content of the 'shopping' cart
Cart::content();
Cart::session('wishlist')->addItem($product_2, ['quantity' => 2], ['size' => 'medium']);
// Get the content of the 'wishlist' cart
Cart::content();
// If you want to get the content of the 'shopping' cart again
Cart::session('shopping')->content();
// And the count of the 'wishlist' cart again
Cart::session('wishlist')->count();
// First we'll add the item to the cart.
$cartItem = Cart::addItem(['id' => 1, 'name' => 'Product 1', 'price' => 9.99], ['quantity' => 2], ['size' => 'large']);
// Next we associate a model with the item.
Cart::associate($cartItem->itemId, 'Product');
// Or even easier, call the associate method on the CartItem!
$cartItem->associate('Product');
// You can even make it a one-liner
Cart::addItem(['id' => 2, 'name' => 'Product 2', 'price' => 9.99], ['quantity' => 1], ['size' => 'large'])->associate('Product');
// Now, when iterating over the content of the cart, you can access the model.
foreach(Cart::content() as $row) {
echo 'You have ' . $row->quantity . ' items of ' . $row->model->name . ' with description: "' . $row->model->description . '" in your cart.';
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.