Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
59 lines (51 sloc) 1.3 KB
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\commerce\elements\actions;
use Craft;
use craft\base\ElementAction;
use craft\helpers\Json;
/**
* Class Create Discount
*
* @property void $triggerHtml the action’s trigger HTML
* @property string $triggerLabel the action’s trigger label
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 2.0
*/
class CreateDiscount extends ElementAction
{
// Public Methods
// =========================================================================
/**
* @inheritdoc
*/
public function getTriggerLabel(): string
{
return Craft::t('commerce', 'Create discount…');
}
/**
* @inheritdoc
*/
public function getTriggerHtml()
{
$type = Json::encode(static::class);
$js = <<<EOT
(function()
{
var trigger = new Craft.ElementActionTrigger({
type: {$type},
batch: true,
activate: function(\$selectedItems)
{
Craft.redirectTo(Craft.getUrl('commerce/promotions/discounts/new', 'purchasableIds='+Craft.elementIndex.getSelectedElementIds().join('|')));
}
});
})();
EOT;
Craft::$app->getView()->registerJs($js);
}
}
You can’t perform that action at this time.