Last active
August 29, 2015 13:59
-
-
Save bryantAXS/10882383 to your computer and use it in GitHub Desktop.
Creating a Store adjuster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Inside our custom third_party addon folder, /third_party/store_helpers, we have a folder called "classes." | |
// Within the classes directory we have this file, which holds our custom build Adjuster Class. | |
// | |
// You should be able to see how this class is passed our $order object, and then instantiates a new | |
// Order Adjustment object, which we use to make the adjustment. There are a few properties on the Order Adjustment | |
// object (nane, type, amount, etc..) that define the adjustment. The adjustment is then returned and processed. | |
namespace Store\Adjuster; | |
require PATH_THIRD.'store'.'/autoload.php'; | |
use Store\Model\Order; | |
use Store\Model\OrderAdjustment; | |
/** | |
* Calculate handling surcharge applicable to an order | |
*/ | |
class DeliveryAdjuster implements AdjusterInterface | |
{ | |
public function adjust(Order $order) | |
{ | |
if($order->order_custom1 == "delivery"){ | |
$adjustment = new OrderAdjustment(); | |
$adjustment->name = "Delivery Charge"; | |
$adjustment->type = 'Delivery'; | |
$adjustment->amount = 4; | |
$adjustment->taxable = 0; | |
$adjustment->included = 0; | |
return array($adjustment); | |
} | |
return array(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an extension (ours is called Store Helpers), and create a hook for the | |
// store_orders_adjuster method, which Store provides. | |
// | |
// Inside the method your going to be loading the custom Adjusters you need, which are included in a seperate file. | |
// In this example I have two custom adjusters, for two seperate adjustments to the order. | |
public function store_order_adjusters($adjusters) | |
{ | |
$adjusters[40] = new Store\Adjuster\DeliveryAdjuster; | |
$adjusters[50] = new Store\Adjuster\TipAdjuster; | |
return $adjusters; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment