Skip to content

Instantly share code, notes, and snippets.

@fritzmg
Created January 15, 2019 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fritzmg/ac2d919c261c94b12d36eb18af5e9670 to your computer and use it in GitHub Desktop.
Save fritzmg/ac2d919c261c94b12d36eb18af5e9670 to your computer and use it in GitHub Desktop.
Custom Contao Isotope Surcharge
<?php
/**
* Register Isotope model types
*/
\Isotope\Model\ProductCollectionSurcharge::registerModelType('mysurcharge', \MySurchargeModel::class);
/**
* Register Isotope hooks
*/
$GLOBALS['ISO_HOOKS']['findSurchargesForCollection'][] = [\MySurcharge::class, 'findSurchargesForCollection'];
<?php
use Isotope\Model\ProductCollection;
class MySurcharge
{
public function findSurchargesForCollection(ProductCollection $collection): array
{
return [\MySurchargeModel::build()];
}
}
<?php
use Isotope\Interfaces\IsotopeProductCollectionSurcharge;
use Isotope\Model\ProductCollectionSurcharge;
class MySurchargeModel extends ProductCollectionSurcharge implements IsotopeProductCollectionSurcharge
{
public static function build(): self
{
$surcharge = new self();
$surcharge->label = 'My Surcharge';
$surcharge->price = '';
$surcharge->total_price = 100.0;
$surcharge->tax_class = 1;
$surcharge->before_tax = true;
$surcharge->addToTotal = true;
return $surcharge;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment