Based on some research, I believe a custom Adjuster is the way to solve this problem.
I created an adjuster with the following:
craft/plugins/myplugin/MypluginPlugin.php
public function commerce_registerOrderAdjusters()
{
return [
401 => new \Commerce\Adjusters\Myplugin_TenpercentDiscount
];
}
craft/plugins/myplugin/Adjusters/Myplugin_TenPercentDiscount.php
<?php
namespace Commerce\Adjusters;
use Craft\Commerce_LineItemModel;
use Craft\Commerce_OrderAdjustmentModel;
use Craft\Commerce_OrderModel;
class Myplugin_TenPercentDiscount implements Commerce_AdjusterInterface {
public function adjust(Commerce_OrderModel &$order, array $lineItems = []){
if (empty($lineItems))
{
return [];
}
if ($order->totalQty >= 10)
{
$adjuster = new Commerce_OrderAdjustmentModel();
$adjuster->type = 'Item Discount';
$adjuster->name = '10% Off Items';
$adjuster->description = 'Your order qualifies for a 10% discount on all non sale items because you are purchasing at least 10 products.';
$adjuster->orderId = $order->id;
$amountOff = 0;
foreach ($lineItems as $item)
{
if (empty($item->onSale))
{
$amountOff += ($item->subtotal + $item->discount) * .1;
}
}
$amountOff = $amountOff * -1;
$adjuster->amount = $amountOff;
$adjuster->optionsJson = ['lineItemsAffected' => null];
$order->baseDiscount += $amountOff;
$adjuster->included = false;
return [$adjuster];
}
return[];
}
}
Does anyone see any flaws with this approach?