Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
BasePrice.php
1<?php
2
4
7use Bitrix\Catalog\v2\HasSettingsTrait;
8
17abstract class BasePrice extends BaseEntity
18{
20
21 public function __construct(PriceRepositoryContract $priceRepository)
22 {
23 parent::__construct($priceRepository);
24 }
25
26 public function setPrice(?float $price): self
27 {
28 $this->setField('PRICE', $price);
29
30 return $this;
31 }
32
33 public function unsetPrice(): self
34 {
35 return $this->setPrice(null);
36 }
37
38 public function hasPrice(): bool
39 {
40 return $this->hasField('PRICE') && is_numeric($this->getField('PRICE'));
41 }
42
43 public function getPrice(): ?float
44 {
45 return $this->hasPrice() ? (float)$this->getField('PRICE') : null;
46 }
47
48 public function setCurrency($currency): self
49 {
50 $this->setField('CURRENCY', $currency);
51
52 return $this;
53 }
54
55 public function getCurrency(): string
56 {
57 return (string)$this->getField('CURRENCY');
58 }
59
60 public function isPriceBase(): bool
61 {
62 return $this->getSetting('BASE') === 'Y';
63 }
64
65 public function setGroupId(int $groupId): self
66 {
67 $this->setField('CATALOG_GROUP_ID', $groupId);
68
69 return $this;
70 }
71
72 public function getGroupId(): int
73 {
74 return (int)$this->getField('CATALOG_GROUP_ID');
75 }
76
77 public function setProductId(int $productId): self
78 {
79 $this->setField('PRODUCT_ID', $productId);
80
81 return $this;
82 }
83
84 public function getProductId(): int
85 {
86 return (int)$this->getField('PRODUCT_ID');
87 }
88
89 protected function getFieldsMap(): array
90 {
91 return [
92 'ID' => MapTypeCaster::NULLABLE_INT,
93 'PRODUCT_ID' => MapTypeCaster::INT,
94 'EXTRA_ID' => MapTypeCaster::NULLABLE_INT,
95 'CATALOG_GROUP_ID' => MapTypeCaster::INT,
96 'PRICE' => MapTypeCaster::NULLABLE_FLOAT,
97 'CURRENCY' => MapTypeCaster::STRING,
98 'TIMESTAMP_X' => MapTypeCaster::DATETIME,
99 'QUANTITY_FROM' => MapTypeCaster::NULLABLE_INT,
100 'QUANTITY_TO' => MapTypeCaster::NULLABLE_INT,
101 ];
102 }
103}
setField(string $name, $value)
__construct(PriceRepositoryContract $priceRepository)
Definition BasePrice.php:21
getSetting(string $name)