Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
payableshipmentitem.php
1<?php
2
3namespace Bitrix\Sale;
4
7
8Main\Localization\Loc::loadMessages(__FILE__);
9
15{
16 public static function getRegistryEntity() : string
17 {
19 }
20
21 public static function getEntityType() : string
22 {
24 }
25
26 public function getPrice(): float
27 {
29 $shipment = $this->getEntityObject();
30
31 if ($shipment)
32 {
33 return $shipment->getPrice();
34 }
35
36 return 0;
37 }
38
39 public function getEntityObject()
40 {
41 if ($this->item === null)
42 {
44 $payment = $this->collection->getPayment();
45
46 $this->item = $payment->getOrder()->getShipmentCollection()->getItemById(
47 $this->getField('ENTITY_ID')
48 );
49 }
50
51 return $this->item;
52 }
53
55 {
56 if (!$entity instanceof Shipment)
57 {
58 throw new Main\SystemException(
59 Main\Localization\Loc::getMessage(
60 'SALE_PAYABLE_ITEM_INCOMPATIBLE_TYPE',
61 ['#CLASS#' => Shipment::class]
62 )
63 );
64 }
65
66 $item = parent::create($collection, $entity);
67
68 $item->setFieldNoDemand('QUANTITY', 1);
69
70 return $item;
71 }
72
73 protected function onFieldModify($name, $oldValue, $value)
74 {
75 if ($name === 'QUANTITY')
76 {
77 if ($value !== 1)
78 {
79 $result = new Result();
80
81 return $result->addError(
82 new Main\Error(
83 Main\Localization\Loc::getMessage('SALE_PAYABLE_ITEM_SHIPMENT_QUANTITY_ERROR')
84 )
85 );
86 }
87 }
88
89 return parent::onFieldModify($name, $oldValue, $value);
90 }
91
97 public static function getEntityEventName()
98 {
99 return 'SalePayableShipmentEntity';
100 }
101
102}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
onFieldModify($name, $oldValue, $value)
static create(PayableItemCollection $collection, CollectableEntity $entity)
const ENTITY_PAYABLE_SHIPMENT
Definition registry.php:24