Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
getbasketaction.php
1<?php
2
4
7
15{
16 private function checkParams(array $fields): Sale\Result
17 {
18 $result = new Sale\Result();
19
20 if (empty($fields['SITE_ID']))
21 {
22 $this->addError(
23 new Main\Error(
24 'siteId not found',
26 )
27 );
28 }
29
30 if (empty($fields['FUSER_ID']) || (int)$fields['FUSER_ID'] <= 0)
31 {
32 $this->addError(
33 new Main\Error(
34 'fuserId not found',
36 )
37 );
38 }
39
40 return $result;
41 }
42
43 public function run(array $fields)
44 {
45 $checkParamsResult = $this->checkParams($fields);
46 if (!$checkParamsResult->isSuccess())
47 {
48 $this->addErrors($checkParamsResult->getErrors());
49 return null;
50 }
51
52 $fuserId = $fields['FUSER_ID'];
53 $basket = $this->getBasketByFuserId($fuserId, $fields['SITE_ID']);
54
55 $registry = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER);
57 $orderClassName = $registry->getOrderClassName();
58 $order = $orderClassName::create($fields['SITE_ID']);
59 $order->setBasket($basket);
60
61 return [
62 'BASKET_ITEMS' => Sale\Helpers\Controller\Action\Entity\Order::getOrderProductsByBasket($basket),
63 'ORDER_PRICE_TOTAL' => Sale\Helpers\Controller\Action\Entity\Order::getTotal($order),
64 ];
65 }
66
67 private function getBasketByFuserId($fuserId, $siteId): Sale\BasketBase
68 {
69 $registry = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER);
70
72 $basketClassName = $registry->getBasketClassName();
73 return $basketClassName::loadItemsForFUser($fuserId, $siteId)->getOrderableItems();
74 }
75}
addError(Error $error)
Definition action.php:200
addErrors(array $errors)
Definition action.php:213