suavy/loja-for-laravel

1.0.15 2021-01-31 10:24 UTC

This package is auto-updated.

Last update: 2022-06-18 16:58:53 UTC


README

Latest Version on Packagist Build Status Quality Score Total Downloads

LOJA is a Laravel package that help you add eCommerce features to your working Laravel application. LOJA comes with a functional backend (easy to add on existing Backpack admin panel, or in a new one) and a DIY frontend.

⚠️ THIS IS CURRENTLY IN DEVELOPMENT AND NOT WORKING

Installation

1️⃣ Install the package via composer:

composer require suavy/loja-for-laravel

Please, note that the package is made for Backpack for Laravel which is free for non-commercial use only.

2️⃣ Follow the Backpack for Laravel installation first if you don't have it already in your project. If you are not familiar with Backpack, it's time to start!

3️⃣ Publish BackpackSettings files (official Backpack addon)

php artisan vendor:publish --provider="Backpack\Settings\SettingsServiceProvider"

4️⃣ Publish our files (that include config file, migrations and views)

php artisan vendor:publish --provider="Suavy\LojaForLaravel\LojaForLaravelServiceProvider"

Please, before continuing, get a look at config/loja.php and fill it! Some configuration are required, so don't forget to do it

5️⃣ Migrate your database

php artisan migrate

6️⃣ Add our LOJA Admin Sidebar to your current Backpack sidebar (located at ressources/views/vendor/backpack/base/inc/sidebar_content.blade.php)

@include('loja::admin.sidebar')

7️⃣ We use Laravel Livewire for some dynamic components (instead of Vue or React), to make theses components work, you need to first include their javascript using their custom blade directives.

<head>
    ...
    @livewireStyles
</head>
<body>
    ...
    @livewireScripts
</body>

8️⃣ Add HasAddress trait to user model

use Suavy\LojaForLaravel\Traits\HasAddress;

class User extends ...
{
    use HasAddress;
}

9️⃣ Add button to backpack admin in views/vendor/backpack/crud/buttons/toggle-country.blade.php // TODO Trie to remove this step

@include('loja::admin.crud.buttons.toggle-country')

Installation is done now 🎉

Usage

Backend

Everything was already done during the installation. So you can start using your backend now 🚀

Frontend (Do It Yourself)

LOJA only create empty views (except for the cart page that is included), but in each view you have access to the needed variables and their attributes to make your own frontend views.

You can add a prefix to every LOJA routes updating the routes_prefix on config file.

GET routes

route route name view variables
/cart loja.cart.index .../cart/index.blade.php $cart
- - .../cart/empty.blade.php -
/categories loja.category.index .../category/index.blade.php $categories
/category/{category} loja.category.show .../category/show.blade.php $category
/collections loja.collection.index .../collection/index.blade.php $collections
/collection/{collection} loja.collection.show .../collection/show.blade.php $collection
/payment/success loja.payment.success .../cart/payment-success.blade.php $cart
/payment/cancel redirects to /cart with message - -
/product/{product} loja.product.show .../product/show.blade.php $product, $relatedProducts
/search?... loja.search .../search/index.blade.php $products
/user/orders loja.user.order.index .../user/order/index.blade.php $orders
/user/order/{order} loja.user.order.show .../user/order/show.blade.php $order

Empty views are located at resources/views/vendor/loja/

Components

name description
"Loja Add To Cart" this components must be added in every product page (loja.product.show)

POST routes

route name parameters description
loja.cart.product.add $product, $quantity add a product to cart
loja.cart.product.remove $product remove a product from cart
loja.cart.empty - empty the cart
loja.cart.product.update.quantity $product, $quantity update product cart quantity

Helper features (available everywhere)

helper function description
loja_categories return a Collection of categories
loja_collections return a Collection of collections
loja_products($params) return a Collection of products