PHP code example of codeiqbv / laravel-mww

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

    

codeiqbv / laravel-mww example snippets


use CodeIQ\LaravelMww\Facades\MyOnlineStore;

// Get all articles
$articles = MyOnlineStore::articles()->get();

// Get all orders
$orders = MyOnlineStore::ordersList()->get();

// Basic listing
$articles = MyOnlineStore::articles()->get();

// With filters
$articles = MyOnlineStore::articles()
    ->limit(50)
    ->offset(0)
    ->createdBetween('2024-01-01 00:00:00', '2024-03-01 23:59:59')
    ->language('en_GB')
    ->get();

// Get count
$count = MyOnlineStore::articles()->count();

// Get single article
$article = MyOnlineStore::articles()->find(123);

// Create article
$articleData = new CreateArticleData(
    name: 'New Product',
    description: 'Product description',
    sku: 'PROD-123',
    price: [
        'default' => 12.50,
        'action' => 9.95
    ]
);
$article = MyOnlineStore::articles()->create($articleData);

// Update article
$updateData = new UpdateArticleData(
    name: 'Updated Name',
    stock: 20
);
$article = MyOnlineStore::articles()->update(123, $updateData);

// Delete article
$success = MyOnlineStore::articles()->delete(123);

// Delete article image
$success = MyOnlineStore::articles()->deleteImage(456);

// Basic listing
$orders = MyOnlineStore::ordersList()->get();

// With filters
$orders = MyOnlineStore::ordersList()
    ->limit(25)
    ->between('2024-01-01', '2024-03-01')
    ->status(1)
    ->archived(true)
    ->forDebtor('[email protected]')
    ->orderBy('desc')
    ->get();

// Get count
$count = MyOnlineStore::ordersList()->count();

// Get single order
$order = MyOnlineStore::ordersList()->find(27);

// Create order
$orderData = new CreateOrderData(
    // ... order details
);
$order = MyOnlineStore::ordersList()->create($orderData);

// Update order
$updateData = new UpdateOrderData(
    status: 2,
    archived: true
);
$order = MyOnlineStore::ordersList()->update(27, $updateData);

// Create credit order
$creditData = new CreateCreditOrderData(
    credited_order_number: '272',
    status: 10
);
$creditOrder = MyOnlineStore::ordersList()->credit($creditData);

// Get order payments
$payments = MyOnlineStore::ordersList()
    ->payments(27, ['properties', 'mutations']);

// Create payment
$paymentData = new CreatePaymentData(
    gateway: 'mollie',
    method: 'ideal'
);
$payment = MyOnlineStore::ordersList()
    ->createPayment(27, $paymentData);

// Update payment
$updateData = new UpdatePaymentData(
    method: 'creditcard'
);
$payment = MyOnlineStore::ordersList()
    ->updatePayment(27, 'payment-id', $updateData);

// Delete payment
$success = MyOnlineStore::ordersList()
    ->deletePayment(27, 'payment-id');

// Get all gateways
$gateways = MyOnlineStore::payments()->gateways();

// Get store-specific gateways
$gateways = MyOnlineStore::payments()
    ->storeGateways('store-id');

// List discount codes
$codes = MyOnlineStore::discountCodes()
    ->active()
    ->validBetween('2024-01-01', '2024-12-31')
    ->get();

// Create discount code
$codeData = new CreateDiscountCodeData(
    description: 'Summer Sale',
    percentage_discount: '10.00'
);
$code = MyOnlineStore::discountCodes()->create($codeData);

// Get single code
$code = MyOnlineStore::discountCodes()->find('SUMMER10');

// Update code
$updateData = new UpdateDiscountCodeData(
    active: false
);
$code = MyOnlineStore::discountCodes()->update('SUMMER10', $updateData);

// Delete code
$success = MyOnlineStore::discountCodes()->delete('SUMMER10');

use YourNamespace\MyOnlineStore\Exceptions\AuthenticationException;
use YourNamespace\MyOnlineStore\Exceptions\ConfigurationException;
use YourNamespace\MyOnlineStore\Exceptions\ValidationException;

try {
    $result = MyOnlineStore::articles()->create($data);
} catch (AuthenticationException $e) {
    // Handle invalid API credentials
} catch (ValidationException $e) {
    $errors = $e->getErrors();
    // Handle validation errors
} catch (ConfigurationException $e) {
    // Handle configuration issues
}

// Enable multi-tenant mode in config
'multi_tenant' => true,

// Set tenant-specific credentials
MyOnlineStore::setTenantCredentials(
    'tenant-api-key',
    'https://tenant-specific-url.com'
);

// Continue using the API as normal
$articles = MyOnlineStore::articles()->get();
bash
php artisan vendor:publish --tag="myonlinestore-config"