PHP code example of philipbrown / merchant

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

    

philipbrown / merchant example snippets


 namespace Philipbrown\Merchant\Region;

use Philipbrown\Merchant\AbstractRegion;
use Philipbrown\Merchant\RegionInterface;

class England extends AbstractRegion implements RegionInterface {

  /**
   * @var string
   */
  protected $name = 'England';

  /**
   * @var string
   */
  protected $currency = 'GBP';

  /**
   * @var boolean
   */
  protected $tax = true;

  /**
   * @var integer
   */
  protected $taxRate = 20;

}

$o = Merchant::order('England');

$o->add('123', 1000);

// Using an array
$o->add('456', 1000, array(
  'discount' => 200,
  'coupon' => 'SUMMERSALE2014'
));

// Using a closure
$o->add('789', 1000, function($item){
  $item->taxable(false);
  $item->quantity(10);
});

$o->remove('456');

// Add product with a discount
$o->add('123', 1000, array(
  'discount' => 200
));

$o->total_value->cents; // 1000
$o->total_discount->cents; // 200

// Update the product to a lower price without a discount
$o->update('123', 800);

$o->total_value->cents; // 800
$o->total_discount->cents; // 200

$o->add('123', 1000);
$o->add('456', 200, array(
  'freebie' => true
));
$o->add('789', 2000, array(
  'discount' => 500
));
$o->add('101112', 1000, array(
  'taxable' => false
));

// Total value of the products (before freebies/discounts/tax)
$o->total_value->cents; // 4200

// Total discount for all products with discounts
$o->total_discount->cents; // 500

// Total tax for taxable products
$o->total_tax->cents; // 500

// Subtotal of all products (before discounts/tax)
$o->subtotal->cents; // 4000

// Total of all products (including discounts/tax)
$o->total->cents; // 4000