Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
payablebasketitem.php
1<?php
2
3namespace Bitrix\Sale;
4
6
7Main\Localization\Loc::loadMessages(__FILE__);
8
14{
15 public static function getRegistryEntity()
16 {
18 }
19
20 public static function getEntityType() : string
21 {
23 }
24
25 public function getPrice(): float
26 {
28 $basketItem = $this->getEntityObject();
29
30 if ($basketItem)
31 {
32 return $basketItem->getPrice();
33 }
34
35 return 0;
36 }
37
38 public static function create(PayableItemCollection $collection, Internals\CollectableEntity $entity)
39 {
40 if (!$entity instanceof BasketItem)
41 {
42 throw new Main\SystemException(
43 Main\Localization\Loc::getMessage(
44 'SALE_PAYABLE_ITEM_INCOMPATIBLE_TYPE',
45 ['#CLASS#' => BasketItem::class]
46 )
47 );
48 }
49
50 return parent::create($collection, $entity);
51 }
52
53 public function getEntityObject()
54 {
55 if ($this->item === null)
56 {
58 $payment = $this->collection->getPayment();
59
60 $this->item = $payment->getOrder()->getBasket()->getItemById(
61 $this->getField('ENTITY_ID')
62 );
63 }
64
65 return $this->item;
66 }
67
68 protected function onFieldModify($name, $oldValue, $value)
69 {
70 if ($name === 'QUANTITY')
71 {
72 $quantity = $this->getEntityObject()->getQuantity();
73 if ($quantity < $value)
74 {
75 $result = new Result();
76
77 return $result->addError(
78 new Main\Error(
79 Main\Localization\Loc::getMessage('SALE_PAYABLE_ITEM_QUANTITY_ERROR')
80 )
81 );
82 }
83 }
84
85 return parent::onFieldModify($name, $oldValue, $value);
86 }
87
93 public static function getEntityEventName()
94 {
95 return 'SalePayableBasketItemEntity';
96 }
97}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
onFieldModify($name, $oldValue, $value)
static create(PayableItemCollection $collection, Internals\CollectableEntity $entity)
const ENTITY_PAYABLE_BASKET_ITEM
Definition registry.php:23