yeknava / simple-shop
simple shop package for laravel
3.0
2025-04-03 12:47 UTC
Requires
- php: >= 8.1
- ext-json: *
- cocur/slugify: ^4.6.0
- illuminate/database: 8.*|9.*|10.*|11.*|12.*
- illuminate/http: 8.*|9.*|10.*|11.*|12.*
- illuminate/support: 8.*|9.*|10.*|11.*|12.*
- nesbot/carbon: ^3.8.4
Requires (Dev)
- fzaninotto/faker: ^1.9
- orchestra/testbench: ^9.9.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.0
README
Laravel Simple Shop Package.
Installation
Use the package manager composer to install simple shop package.
composer require yeknava/simple-shop
Usage
Run this command in your terminal:
php artisan vendor:publish
Add SimpleShopOwner trait to Shop owner models and Add SimpleShopCustomer trait to customer models if there is any.
<?php
use Yeknava\SimpleShop\SimpleShopCustomer;
class User extends Model {
use SimpleShopCustomer;
}
<?php
use Yeknava\SimpleShop\SimpleShopOwner;
class OwnerModel extends Model {
use SimpleShopOwner;
}
$customer = (new UserModel([]));
$customer->save();
$shopOwner = (new OwnerModel([]));
$shopOwner->save();
$shopOwner->newShop('shop title');
$this->assertEquals($shopOwner->shops()->count(), 1);
$shop = $shopOwner->shop();
$product = $shop->addProduct('product 1 title', 10000, null, [
'description' => 'product 1 desc',
'quantity' => 100
]);
$customer->addToCart($product, 90, ['color'=>'red']);
$customer->addToCart($product, 1, ['color'=>'blue']);
$this->assertEquals(2, count($customer->cart->items));
$customer->addToCart($product, 10, ['color'=>'red']);
$this->assertEquals(3, count($customer->cart()->first()->items));
// clearing cart won't decrease product quantity
$customer->clearCart();
$this->assertEquals(0, count($customer->cart()->first()->items));
$customer->addToCart($product, 10, ['color'=>'red']);
$this->assertEquals(1, count($customer->cart()->first()->items));
$product = $shop->searchByTitle('product 1 title');
$this->assertEquals('product 1 title', $product->title);
$this->assertEquals(100, $product->quantity);
// purchasing cart will decrease product quantity
$customer->cartPurchased();
$product = $shop->searchByTitle('product 1 title');
$this->assertEquals(90, $product->quantity);
// shop specific cart instance for each customer
$customer->addToCart($product, 1, ['color'=>'red'], $shop->id);
$this->assertEquals(1, $customer->cart($shop->id)->first()->items[0]['quantity']);
// default cart instance for each customer
$customer->addToCart($product, 10, ['color'=>'red']);
$this->assertEquals(10, $customer->cart()->first()->items[0]['quantity']);
Order Status Flow
success: Created -> Paid -> Fulfilled failed: Created | Paid | Fulfilled -> Canceled returned: Created -> Paid | Fulfilled -> Returned
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.