dynamic / silverstripe-foxy-discounts
Offer discounts on purchase conditions for your Foxy products.
Installs: 557
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 2
Open Issues: 2
Type:silverstripe-vendormodule
Requires
- dynamic/silverstripe-foxy: ^1.3.2
Requires (Dev)
- pdepend/pdepend: ^2.5
- phploc/phploc: ^4.0
- phpmd/phpmd: ^2.6
- phpunit/phpunit: ^5.7
- sebastian/phpcpd: ^3.0
- squizlabs/php_codesniffer: ^3.0
- theseer/phpdox: ^0.11.0
README
Offer discounts on purchase conditions for your Foxy products.
Requirements
- SilverStripe ^4.0
- SilverStripe Foxy ^1.0
Installation
composer require dynamic/silverstripe-foxy-discounts
License
See License
Example configuration
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
Advanced Usage
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
Maintainers
Bugtracker
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:
- Create a new issue
- Describe the steps required to reproduce your issue, and the expected outcome. Unit tests, screenshots and screencasts can help here.
- Describe your environment as detailed as possible: SilverStripe version, Browser, PHP version, Operating System, any installed SilverStripe modules.
Please report security issues to the module maintainers directly. Please don't file security issues in the bugtracker.
Development and contribution
If you would like to make contributions to the module please ensure you raise a pull request and discuss with the module maintainers.