Skip to content

Instantly share code, notes, and snippets.

@flayder
Last active September 6, 2022 11:43
Show Gist options
  • Save flayder/b06c3a413d149f87dbdb6a074abbd14d to your computer and use it in GitHub Desktop.
Save flayder/b06c3a413d149f87dbdb6a074abbd14d to your computer and use it in GitHub Desktop.
function applyDiscount(string $coupon) {
$is_unused = Sale\DiscountCouponsManager::getEnteredCoupon($coupon);
if(!$is_unused) {
Sale\DiscountCouponsManager::add($coupon);
$oBasket = Sale\Basket::loadItemsForFUser(
Sale\Fuser::getId(),
Main\Context::getCurrent()->getSite()
);
$oDiscounts = Sale\Discount::loadByBasket($oBasket);
$oBasket->refreshData(['PRICE', 'COUPONS']);
$oDiscounts->calculate();
$oDiscounts->getApplyResult();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment