PHP code example of marshmallow / cart

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

    

marshmallow / cart example snippets


protected $middlewareGroups = [
    'web' => [
        // ...
        \Marshmallow\Ecommerce\Cart\Http\Middleware\CartMiddleware::class,
    ],
];

use Marshmallow\Ecommerce\Cart\Facades\Cart;
use Marshmallow\Ecommerce\Cart\Models\Discount;

$discount = Discount::byCode(
    request()->discount
);

$response = Cart::get()->addDiscount($discount);

use Marshmallow\Ecommerce\Cart\Facades\Cart;

Cart::get()->deleteDiscount();

$cart->getTotalAmountWithoutShippingAndDiscount();
$cart->getTotalAmountWithoutShippingAndDiscountAndWithoutVat();
$cart->getDiscountAmount();
$cart->getDiscountAmountWithoutVat();

/**
 * These are helper functions to get cart totals.
 */
$cart->getTotalAmountWithoutShipping();
$cart->getTotalAmountWithoutShippingAndWithoutVat();
$cart->getShippingAmount();
$cart->getShippingAmountWithoutVat();
$cart->getTotalAmount();
$cart->getTotalAmountWithoutVat();
$cart->getTotalVatAmount();
$cart->getTotalAmountWithoutShippingAndDiscount();
$cart->getTotalAmountWithoutShippingAndDiscountAndWithoutVat();
$cart->getDiscountAmount();
$cart->getDiscountAmountWithoutVat();

/**
 * You can format all the methods above to get a string with currency.
 */
$cart->getFormatted('getTotalAmount');

/**
 * Extra helpers
 */
$cart->productCount();
$cart->getItemsWithoutShipping();
$cart->getItemsWithoutDiscount();
$cart->getDiscountItems();
$cart->getItemsWithoutDiscountAndShipping();
$cart->getOnlyProductItems();

$item->setQuantity(4);
$item->increaseQuantity();
$item->decreaseQuantity();

// Amount helpers
$item->getUnitAmount();
$item->getUnitAmountWithVat();
$item->getUnitAmountWithoutVat();
$item->getUnitVatAmount();
$item->getTotalAmount();
$item->getTotalAmountWithVat();
$item->getTotalAmountWithoutVat();
$item->getTotalVatAmount();

// Formatted
$item->getFormatted('getTotalAmount');
bash
php artisan migrate
bash
php artisan marshmallow:resource Product Product
php artisan marshmallow:resource ProductCategory Product
php artisan marshmallow:resource Supplier Product
php artisan marshmallow:resource Price Priceable
php artisan marshmallow:resource VatRate Priceable
php artisan marshmallow:resource Currency Priceable
php artisan marshmallow:resource Prospect Ecommerce\\Cart
php artisan marshmallow:resource ShoppingCart Ecommerce\\Cart
php artisan marshmallow:resource Customer Ecommerce\\Cart
php artisan marshmallow:resource ShippingMethod Ecommerce\\Cart
php artisan marshmallow:resource ShippingMethodCondition Ecommerce\\Cart
php artisan marshmallow:resource Order Ecommerce\\Cart
php artisan marshmallow:resource OrderItem Ecommerce\\Cart
php artisan marshmallow:resource Discount Ecommerce\\Cart
php artisan marshmallow:resource Route Seoable
bash
php artisan db:seed --class=Marshmallow\\Priceable\\Seeders\\CurrencySeeder
php artisan db:seed --class=Marshmallow\\Priceable\\Seeders\\VatRatesSeeder
bash
php artisan marshmallow:resource Discount Ecommerce\\Cart
bash
php artisan vendor:publish --tag="ecommerce-discount-config"