PHP code example of phil / commerce-product-template
1. Go to this page and download the library: Download phil/commerce-product-template 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/ */
phil / commerce-product-template example snippets
use Phil\CommerceProductTemplate\{Artwork, Axis, AxisValue, Design, Exclusion, Face, Label, LanguageVersion};
use Phil\CommerceProductTemplate\{Pricing, PrintZone, SkuPattern, Swatch, Template, VariantPlanner};
use Phil\Money\{Currency, Money};
$cad = static fn (int $cents): Money => Money::of($cents, Currency::of('CAD'));
$shirt = Template::of('unisex', Label::of(['en' => 'Unisex shirt', 'fr' => 'T-shirt unisexe']),
SkuPattern::parse('{design}{lang}{version}{size}{colour}'),
Pricing::of($cad(2_500))->withPrice('size', '2X', $cad(2_800))->withSupplement('version', 'C', $cad(1_000)),
[
Axis::of('version', Label::of(['en' => 'Version']),
AxisValue::of('O', Label::of(['en' => 'Regular'])),
AxisValue::of('C', Label::of(['en' => 'Convention']), channels: ['convention'])),
Axis::of('size', Label::of(['en' => 'Size']),
AxisValue::of('M', Label::of(['en' => 'M'])), AxisValue::of('2X', Label::of(['en' => '2XL']))),
Axis::of('colour', Label::of(['en' => 'Colour']),
AxisValue::of('BK', Label::of(['en' => 'Black']), Swatch::colour('#1A1A1A'), 'black', ['front' => 'blanks/front-bk.jpg']),
AxisValue::of('PK', Label::of(['en' => 'Pink']), Swatch::colour('#F4A7C0'), 'azalea')),
],
[Face::of('front', Label::of(['en' => 'Front']), PrintZone::of('chest', 50, 60, 300, 400))],
[Exclusion::of(['colour' => ['PK'], 'size' => ['2X']])],
);
$gnome = Design::of('NAQ001', Label::of(['fr' => 'Le gnome', 'en' => 'The gnome']),
[LanguageVersion::of('F', 'fr'), LanguageVersion::of('E', 'en')],
[Artwork::of('front', 'art/naq001-front.png'), Artwork::of('front', 'art/naq001-front-en.png', language: 'E')]);
foreach (new VariantPlanner()->plan($shirt, $gnome) as $variant) {
echo $variant->sku, ' ', $variant->price->toDecimal(), ' ', $variant->name('en'), "\n";
}
// NAQ001FOMBK 25.00 Le gnome – T-shirt unisexe (Regular, M, Black)
// ...