PHP code example of ingenius / shopcart

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

    

ingenius / shopcart example snippets




namespace YourPackage\CartModifiers;

use Ingenius\ShopCart\Modifiers\BaseCartModifier;
use Ingenius\ShopCart\Services\ShopCart;

class YourModifier extends BaseCartModifier
{
    /**
     * Set priority - lower numbers run first
     */
    public function getPriority(): int
    {
        return 50; // Run after the base item subtotal calculations
    }
    
    /**
     * Modify the subtotal
     */
    public function calculateSubtotal(ShopCart $cart, float $currentSubtotal): float
    {
        // Your custom calculation logic here
        $yourModification = 10.00;
        
        // Store data for use in extendCartArray
        $this->yourData = $yourModification;
        
        // Return modified subtotal
        return $currentSubtotal + $yourModification;
    }
    
    /**
     * Add data to the cart array
     */
    public function extendCartArray(ShopCart $cart, array $cartArray): array
    {
        $cartArray['your_data'] = [
            'amount' => $this->yourData,
            'other_info' => 'Custom information'
        ];
        
        return $cartArray;
    }
    
    protected $yourData;
}



namespace YourPackage\Providers;

use Illuminate\Support\ServiceProvider;
use Ingenius\ShopCart\Services\CartModifierManager;
use YourPackage\CartModifiers\YourModifier;

class YourPackageServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        // Register your cart modifier
        $this->app->afterResolving(CartModifierManager::class, function (CartModifierManager $manager) {
            $manager->register(new YourModifier());
        });
    }
}

// Usage examples will go here
bash
php artisan shopcart:modifiers