1. Go to this page and download the library: Download yabhq/laravel-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/ */
yabhq / laravel-cart example snippets
use Yab\ShoppingCart\Traits\Purchaseable;
use Yab\ShoppingCart\Contracts\Purchaseable as PurchaseableInterface;
class Product extends Model implements PurchaseableInterface
{
use Purchaseable;
}
use Yab\ShoppingCart\Traits\Purchaser;
use Yab\ShoppingCart\Contracts\Purchaser as PurchaserInterface;
class Customer extends Model implements PurchaserInterface
{
use Purchaser;
}
Route::group(['middleware' => ['example']], function () {
use Yab\ShoppingCart\Checkout;
$checkout = Checkout::create();
// or
$checkout = Checkout::findById('uuid-123');
// Add 1 qty of product and return the CartItem model
$item = $checkout->addItem($product, 1);
// Override the default unit price for the product
$item = $checkout->addItem($product, 1, 11.95);
// Add custom options to a checkout item
$item = $checkout->addItem(
purchaseable: $product,
qty: 1,
options: [ 'size' => 'medium' ],
);
// Update the quantity of the item to 2
$checkout->updateItem($item->id, 2);
// Remove the item entirely
$checkout->removeItem($item->id);
public static function getTaxes(Checkout $checkout) : float
public static function getShippingCost(Checkout $checkout) : float
public static function getDiscountFromCode(Checkout $checkout, string $code) : float
public static function getPurchaseable(string $type, mixed $id) : mixed
public static function beforeCartItemAdded(Checkout $checkout, mixed $purchaseable, int $qty) : void
public static function hasInfoNeededToCalculateTotal(Checkout $checkout) : bool