Skip to content
Offer discounts on purchase conditions for your Foxy products
PHP JavaScript
Branch: 1.1
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/ISSUE_TEMPLATE Composer and README updates (#1) Jul 19, 2019
_config refactor - remove extensions from config (#8) Aug 27, 2019
client
src REFACTOR remove FoxyAdminExtension, update docs Nov 19, 2019
tests FEATURE apply discounts to products (#5) Jul 20, 2019
.gitattributes initial commit Jul 19, 2019
.gitignore ENHANCEMENT FE discount price update (#16) Sep 22, 2019
.scrutinizer.yml initial commit Jul 19, 2019
.travis.yml BUGFIX Travis phpcs tests (#31) Oct 30, 2019
CHANGELOG.md
CONTRIBUTING.md initial commit Jul 19, 2019
Jenkinsfile BUGFIX Jenkinsfile - fail test if phpcs doesn’t pass (#32) Oct 30, 2019
LICENSE.md initial commit Jul 19, 2019
README.md REFACTOR remove FoxyAdminExtension, update docs Nov 19, 2019
_config.php initial commit Jul 19, 2019
code-of-conduct.md initial commit Jul 19, 2019
composer.json ENHANCEMENT FE discount price update (#16) Sep 22, 2019
gulpfile.js ENHANCEMENT FE discount price update (#16) Sep 22, 2019
package.json ENHANCEMENT FE discount price update (#16) Sep 22, 2019
phpcs.xml.dist initial commit Jul 19, 2019
phpdox.xml Composer and README updates (#1) Jul 19, 2019
phpunit.xml.dist

README.md

SilverStripe Foxy Discounts

Offer discounts on purchase conditions for your Foxy products.

Build Status Scrutinizer Code Quality Build Status codecov

Latest Stable Version Total Downloads Latest Unstable Version License

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.

You can’t perform that action at this time.