PHP code example of yiddishe-kop / laravel-commerce

1. Go to this page and download the library: Download yiddishe-kop/laravel-commerce 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/ */

    

yiddishe-kop / laravel-commerce example snippets


public function logout(Request $request) {
    $this->guard()->logout();

    // keep cart data for after logout
    $cartId = session()->get('cart');
    $request->session()->invalidate();
    $request->session()->regenerateToken();
    session()->put('cart', $cartId);

    if ($response = $this->loggedOut($request)) {
        return $response;
    }

    return $request->wantsJson()
        ? new JsonResponse([], 204)
        : redirect('/');
}

use YiddisheKop\LaravelCommerce\Contracts\Purchasable;
use YiddisheKop\LaravelCommerce\Traits\Purchasable as PurchasableTrait;

class Product implements Purchasable {
  use PurchasableTrait;

    // the title of the product
    public function getTitle(): string {
        return $this->name;
    }

    // the price
    public function getPrice(): int {
        return $this->price;
    }
}

Cart::add(Purchasable $product, int $quantity = 1);

$product->addToCart($quantity = 1);

Cart::remove(Purchasable $product);

$product->removeFromCart();

Cart::empty();

$cartItems = $cart->items;

$product = $cart->items[0]->model;

Cart::calculateTotals();


use YiddisheKop\LaravelCommerce\Traits\HasOrders;

class User {
  use HasOrders;
  // ...
}

// you can now get all the users' orders (status complete)
$orders = $user->orders;
bash
php artisan vendor:publish --provider="YiddisheKop\LaravelCommerce\CommerceServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="YiddisheKop\LaravelCommerce\CommerceServiceProvider" --tag="migrations"