Files
Admin Nasledstvo ac168868ee Initial import
2026-05-01 20:52:04 +03:00

100 lines
2.6 KiB
PHP

<?php
namespace app\models;
use app\models\parsed\CartInterface;
use app\models\parsed\CartModel;
use app\services\Cart;
/**
* Class Subscriptions
* @package app\models
* @property $price
* @property $name
* @property $name_en
* @property $text
* @property $text_en
* @property $months
* @property $cartKey
*/
class Subscriptions extends _Base implements CartInterface
{
public static function allSelectedSubscriptions()
{
$selected = [];
if (!empty($_COOKIE['cart_data'])) {
$cart_data = json_decode($_COOKIE['cart_data']);
foreach (self::find()->all() as $sb) {
if (in_array($sb->cartKey, $cart_data)) {
$selected[] = $sb->cartKey;
}
}
}
return $selected;
}
public function getTitle()
{
return \Yii::$app->language == 'en' ? $this->name_en : $this->name;
}
public function getDescription()
{
return \Yii::$app->language == 'en' ? $this->text : $this->text_en;
}
public function getFormatedPrice()
{
return number_format($this->price, 2, '.', ' ') . ' лв.';
}
public function getMonthLabel()
{
if ($this->months > 1 || $this->months == 0) {
return Ts::get(86);
} else {
return Ts::get(85);
}
}
public function isInCart()
{
if (!empty($_COOKIE['cart_data']) && in_array($this->cartKey, json_decode($_COOKIE['cart_data'])))
return true;
return false;
}
public function isBtnDisabled()
{
$selected = self::allSelectedSubscriptions();
if (sizeof($selected) > 0 && !in_array($this->cartKey, $selected)) {
return 'disabled';
}
return '';
}
public function getCartKey()
{
return Cart::encodeKey('Subscriptions', $this->id);
}
public function setCart(CartModel $model)
{
$model->title = Ts::get(97) . ' - ' . $this->getTitle();
$model->subTitle = $this->months . ' ' . $this->getMonthLabel();
$model->description = $this->getDescription();
$model->singlePrice = $this->getFormatedPrice();
$model->price = $this->price;
$model->availableQuantity = 1;
/********************************/
$model->name_bg = $this->name . ' (абонамент)';
$model->name_en = $this->name_en. ' (subscription)';
$model->text_bg = $this->text. " ($this->months м)";
$model->text_en = $this->text_en. " ($this->months m)";
return $model;
}
}