PHP code example of misaf / vendra-product

1. Go to this page and download the library: Download misaf/vendra-product 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/ */

    

misaf / vendra-product example snippets


use Misaf\VendraProduct\Models\ProductCategory;

$category = ProductCategory::query()->create([
    'name' => ['en' => 'Beverages'],
    'description' => ['en' => 'Cold and hot drinks'],
    'slug' => ['en' => 'beverages'],
    'active' => true,
]);

use Misaf\VendraProduct\Models\Product;

$product = Product::query()->create([
    'product_category_id' => $category->id,
    'name' => ['en' => 'Orange Juice'],
    'description' => ['en' => 'Fresh and natural'],
    'slug' => ['en' => 'orange-juice'],
    'quantity' => 20,
    'stock_threshold' => 5,
    'in_stock' => true,
    'available_soon' => false,
]);

use Misaf\VendraProduct\Models\ProductPrice;

ProductPrice::query()->create([
    'product_id' => $product->id,
    'currency_code' => 'USD',
    'price' => 9900,
]);

$products = Product::query()
    ->with(['productCategory', 'latestProductPrice'])
    ->get();

use Misaf\VendraProduct\Data\ProductPurchaseQuote;
use Misaf\VendraProduct\Data\ProductPurchaseRequest;
use Misaf\VendraProduct\Services\ProductPurchaseQuoter;

$quotes = app(ProductPurchaseQuoter::class)->quote([
    'line-1' => new ProductPurchaseRequest(productId: $product->id, quantity: 2),
], 'USD');

$quote = $quotes['line-1']; // ProductPurchaseQuote, or a ProductPurchaseRefusalEnum case

use Misaf\VendraTagger\Models\Tagger;

$tag = Tagger::findOrCreate('Featured', type: 'product', locale: 'en');

$product->tags()->sync([$tag->getKey()]);
bash
composer vendor:publish --tag=vendra-product-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=vendra-product-config
php artisan vendor:publish --tag=vendra-product-translations
bash
php artisan test --compact --testsuite=vendra-product
composer stan