Your IP : 52.14.144.75
<?php
/**
* User: Rodion Abdurakhimov
* Date: 24/6/16
* Time: 11:36
*/
namespace Epages;
class DiscountCoupons
{
/**
* Returns status of coupon
* @param $coupon
* @return mixed
* @throws \Bitrix\Main\ArgumentException
* @throws \Exception
*/
public static function getCouponStatus($coupon)
{
$couponResult = self::getCouponData($coupon);
if (is_array($couponResult) && count($couponResult) > 0) {
return $couponResult['used'];
} else {
throw new \Exception("Купон $coupon не найден");
}
}
public static function setCouponAsUsed($coupon)
{
$couponResult = self::getCouponData($coupon);
if (is_array($couponResult) && count($couponResult) > 0) {
DiscountCouponsTable::update($couponResult['id'], ['used' => 'Y']);
} else {
throw new \Exception("Купон $coupon не найден");
}
}
protected static function getCouponData($coupon)
{
if (strlen($coupon) > 0) {
return DiscountCouponsTable::getList([
'filter' => [
'coupon' => $coupon
]
])->fetch();
} else {
throw new \InvalidArgumentException('Купон должен быть строкой');
}
}
}