Offer discounts on purchase conditions for your Foxy products.
Offer discounts on purchase conditions for your Foxy products.
composer require dynamic/silverstripe-foxy-discounts
See License
Add the following extensions to your product classes:
Dynamic\Products\Page\Product:
extensions:
- Dynamic\Foxy\Discounts\Extension\ProductDataExtension
PageController:
extensions:
- Dynamic\Foxy\Discounts\Extension\PageControllerExtension
You can limit discounts based on Product restrictions. The example below would add a "Discount only these products" and "These products should be excluded from the discount" type of logic:
note: This example has additional requirements such as GridFieldExtension be installed
<?
namespace {
use SilverStripe\ORM\DataExtension;
use Dynamic\Products\Page\Product;
class DiscountDataExtension extends DataExtension
{
/**
* @var array
*/
private static $many_many = [
'Products' => Product::class,
'ExcludeProducts' => Product::class,
];
/**
* @param FieldList $fields
*/
public function updateCMSFields(FieldList $fields)
{
if ($this->owner->ID) {
// Products
$field = $fields->dataFieldByName('Products');
$fields->removeByName('Products');
$fields->addFieldToTab('Root.Included', $field);
$field->setDescription('Limit the discount to these products. If no products specified, all products will receive the discount');
$config = $field->getConfig();
$config
->removeComponentsByType([
GridFieldAddExistingAutocompleter::class,
GridFieldAddNewButton::class,
GridFieldArchiveAction::class,
])
->addComponents([
new GridFieldAddExistingSearchButton(),
]);
$exclusions = $fields->dataFieldByName('ExcludeProducts');
$fields->removeByName('ExcludeProducts');
$fields->addFieldToTab('Root.Excluded', $exclusions);
$exclusions->setDescription('Products in this list will ALWAYS be excluded from the discount, even if added to the "Included" tab.');
$excludeConfig = $exclusions->getConfig();
$excludeConfig
->removeComponentsByType([
GridFieldAddExistingAutocompleter::class,
GridFieldAddNewButton::class,
GridFieldArchiveAction::class,
])
->addComponents([
new GridFieldAddExistingSearchButton(),
]);
}
}
/**
* @return array
*/
public function getRestrictions()
{
if ($this->owner->Products()->count() == 0) {
$products = Product::get()->column();
} else {
$products = $this->owner->Products()->column();
}
foreach ($this->owner->ExcludeProducts()->column() as $id) {
if (in_array($id, $products)) {
$key = array_search($id, $products);
unset($products[$key]);
}
}
return $products;
}
}
}
And apply to Discount
in foxy.yml
:
Dynamic\Foxy\Discounts\Model\Discount:
extensions:
- DiscountDataExtension
Bugs are tracked in the issues section of this repository. Before submitting an issue please read over
existing issues to ensure yours is unique.
If the issue does look like a new bug:
Please report security issues to the module maintainers directly. Please don't file security issues in the bugtracker.
If you would like to make contributions to the module please ensure you raise a pull request and discuss with the module maintainers.
Module rating system helping users find modules that are well supported. For more on how the rating system works visit Module standards
Score not correct? Let us know there is a problem