25 PayableBasketItem::class,
27 function($className, $id) {
33 $pi = $payableItemCollection::getList([
34 'select'=>[
'PAYMENT_ID'],
41 if($piRow = $pi->fetch())
45 $paymentClass = $registry->getPaymentClassName();
47 $r = $paymentClass::getList([
48 'select'=>[
'ORDER_ID'],
49 'filter'=>[
'ID'=>$piRow[
'PAYMENT_ID']]
52 if($row = $r->fetch())
55 $orderClass = $registry->getOrderClassName();
57 $order = $orderClass::load($row[
'ORDER_ID']);
58 $payment = $order->getPaymentCollection()->getItemById($piRow[
'PAYMENT_ID']);
59 $payableItemCollection = $payment->getPayableItemCollection();
61 foreach ($payableItemCollection as $item)
63 if($item->getId() == $id)
71 $this->addError(
new Error(
'payment is not exists', 200640400001));
75 $this->addError(
new Error(
'payment item is not exists', 201240400001));
84 $view = $this->getViewManager()
87 return [
'PAYMENT_ITEM_BASKET'=>$view->prepareFieldInfos(
94 return [
'PAYMENT_ITEM_BASKET'=>$paymentItem->toArray()];
97 public function listAction(
PageNavigation $pageNavigation, array $select = [], array $filter = [], array $order = []):
Page
99 $select = empty($select) ? [
'*'] : $select;
100 $order = empty($order) ? [
'ID'=>
'ASC'] : $order;
107 $paymentItems = $payableItemCollection::getList(
112 'offset' => $pageNavigation->
getOffset(),
113 'limit' => $pageNavigation->
getLimit(),
117 return new Page(
'PAYMENT_ITEMS_BASKET', $paymentItems,
function() use ($filter)
123 return (
int) $payableItemCollection::getList([
133 public function addAction(array $fields): ?array
135 $result =
new Result();
140 $basketId = $fields[
'BASKET_ID'];
141 $paymentId = $fields[
'PAYMENT_ID'];
143 unset($fields[
'PAYMENT_ID'], $fields[
'BASKET_ID']);
146 $basketClass = $registry->getBasketClassName();
148 $r = $basketClass::getList([
149 'select'=>[
'ORDER_ID'],
150 'filter'=>[
'ID'=>$basketId]
153 if($row = $r->fetch())
156 $orderClass = $registry->getOrderClassName();
158 $order = $orderClass::load($row[
'ORDER_ID']);
159 $basketItem = $order->getBasket()->getItemByBasketCode($basketId);
160 if($basketItem instanceof BasketItem)
163 $collection = $order->getPaymentCollection();
164 $payment = $collection->getItemById($paymentId);
167 $paymentItems = $payment->getPayableItemCollection()->getBasketItems();
168 if($this->isExistBasketItem($paymentItems, $basketItem) ==
false)
171 $paymentItem = $payment->getPayableItemCollection()->createItemByBasketItem($basketItem);
172 $result = $paymentItem->setFields($fields);
173 if($result->isSuccess() && $result->hasWarnings() ==
false)
175 $r = $this->save($paymentItem);
178 $result->addErrors($r->getErrors());
184 $result->addError(
new Error(
'Duplicate entry for key [basketId, paymentId]', 201250000001));
189 $result->addError(
new Error(
'payment not exists', 201240400002));
195 $result->addError(
new Error(
'basket item not exists', 201240400003));
198 if(!$result->isSuccess())
203 elseif($result->hasWarnings())
205 $this->
addErrors($result->getWarnings());
208 elseif($paymentItem instanceof PayableItem)
210 return [
'PAYMENT_ITEM_BASKET'=>$paymentItem->toArray()];
214 return [
'PAYMENT_ITEM_BASKET'=>$paymentItem];
220 $r = $paymentItem->setFields($fields);
222 if($r->isSuccess() ==
false)
224 $this->addErrors($r->getErrors());
227 elseif($r->hasWarnings())
229 $this->addErrors($r->getWarnings());
234 $r = $this->save($paymentItem);
237 $this->addErrors($r->getErrors());
242 return [
'PAYMENT_ITEM_BASKET'=>$paymentItem->toArray()];
249 $r = $paymentItem->
delete();
251 if($r->isSuccess() ==
false)
253 $this->addErrors($r->getErrors());
256 elseif($r->hasWarnings())
258 $this->addErrors($r->getWarnings());
263 $r = $this->save($paymentItem);
266 $this->addErrors($r->getErrors());
283 $payment = $collectionPaymentItems->getPayment();
285 $collectionPayments = $payment->getCollection();
286 $order = $collectionPayments->getOrder();
291 $result->addErrors($r->getErrors());
293 elseif($r->hasWarnings())
295 $result->addErrors($r->getWarnings());
300 protected function isExistBasketItem(CollectionFilterIterator $paymentItems, BasketItem $basketItem): bool
302 foreach ($paymentItems as $paymentItem)
305 $entityBasketItem = $paymentItem->getEntityObject();
306 if($entityBasketItem->getBasketCode() === $basketItem->getBasketCode())
319 if ($saleModulePermissions <
"W")
321 $r->addError(
new Error(
'Access Denied', 200040300020));
331 if ($saleModulePermissions ==
"D")
333 $r->addError(
new Error(
'Access Denied', 200040300010));