PHP code example of craftcms / commerce-sagepay
1. Go to this page and download the library: Download craftcms/commerce-sagepay library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
craftcms / commerce-sagepay example snippets
use \craft\commerce\omnipay\base\Gateway as BaseGateway;
Event::on(BaseGateway::class, BaseGatewa::EVENT_AFTER_CREATE_ITEM_BAG, function(ItemBagEvent $itemBagEvent) {
$orderLineItems = $itemBagEvent->order->getLineItems();
/**
* @var $item Item
*/
foreach ($itemBagEvent->items as $key => $item) {
if (!isset($orderLineItems[$key])) {
return;
}
$orderLineItem = $orderLineItems[$key];
// Make sure that the description and price are the same as we are relying upon the order
// of the Order Items and The OmniPay Item Bag to be the same
if ($orderLineItem->getDescription() != $item->getDescription()) {
return;
}
if ($orderLineItem->price != $item->getPrice()) {
return;
}
$sku = $orderLineItem->getSku();
// Place the SKU within [] as the Product Record for the Sage 50 Accounts Integration
$description = '[' . $sku . ']' . $item->getDescription();
$item->setDescription($description);
}
});