diff --git a/install/components/opensource/order/.parameters.php b/install/components/opensource/order/.parameters.php index c625928..f5c580c 100644 --- a/install/components/opensource/order/.parameters.php +++ b/install/components/opensource/order/.parameters.php @@ -67,6 +67,12 @@ 'MULTIPLE' => 'N', 'DEFAULT' => '/personal/cart/', 'PARENT' => 'ADDITIONAL_SETTINGS', - ] + ], + 'ALLOW_UNAUTH_ORDER' => [ + 'NAME' => Loc::getMessage('OPEN_SOURCE_ORDER_ALLOW_UNAUTH_ORDER'), + 'TYPE' => 'CHECKBOX', + 'DEFAULT' => 'N', + 'PARENT' => 'ADDITIONAL_SETTINGS', + ], ] ]; \ No newline at end of file diff --git a/install/components/opensource/order/class.php b/install/components/opensource/order/class.php index ebf26b4..07b9bb2 100644 --- a/install/components/opensource/order/class.php +++ b/install/components/opensource/order/class.php @@ -116,6 +116,11 @@ public function createVirtualOrder(int $personTypeId) throw new RuntimeException(Loc::getMessage('OPEN_SOURCE_ORDER_UNKNOWN_PERSON_TYPE')); } + $userID = intval($USER->GetID()); + if( ! $userID && 'Y' !== $this->arParams['ALLOW_UNAUTH_ORDER'] ) { + throw new RuntimeException(Loc::getMessage('OPEN_SOURCE_ORDER_USER_NOT_AUTH')); + } + $siteId = Context::getCurrent() ->getSite(); @@ -126,7 +131,7 @@ public function createVirtualOrder(int $personTypeId) throw new LengthException(Loc::getMessage('OPEN_SOURCE_ORDER_EMPTY_BASKET')); } - $this->order = Order::create($siteId, $USER->GetID()); + $this->order = Order::create($siteId, $userID ?: CSaleUser::GetAnonymousUserID()); $this->order->setPersonTypeId($personTypeId); $this->order->setBasket($basketItems); diff --git a/install/components/opensource/order/lang/ru/.parameters.php b/install/components/opensource/order/lang/ru/.parameters.php index f974b50..0cebe64 100644 --- a/install/components/opensource/order/lang/ru/.parameters.php +++ b/install/components/opensource/order/lang/ru/.parameters.php @@ -5,4 +5,5 @@ $MESS['OPEN_SOURCE_ORDER_DEFAULT_PAY_SYSTEM_ID'] = 'Платежная система по умолчанию'; $MESS['OPEN_SOURCE_ORDER_USE_DEFAULT_USER_ID'] = 'Сохранять заказ на указанного пользователя, если покупатель не авторизован'; $MESS['OPEN_SOURCE_ORDER_DEFAULT_USER_ID'] = 'ID пользователя битрикс для заказов без авторизации'; -$MESS['OPEN_SOURCE_ORDER_PATH_TO_BASKET'] = 'Путь до раздела с корзиной'; \ No newline at end of file +$MESS['OPEN_SOURCE_ORDER_PATH_TO_BASKET'] = 'Путь до раздела с корзиной'; +$MESS['OPEN_SOURCE_ORDER_ALLOW_UNAUTH_ORDER'] = 'Разрешить заказ без авторизации'; \ No newline at end of file diff --git a/install/components/opensource/order/lang/ru/class.php b/install/components/opensource/order/lang/ru/class.php index 52f6bb8..6640097 100644 --- a/install/components/opensource/order/lang/ru/class.php +++ b/install/components/opensource/order/lang/ru/class.php @@ -8,4 +8,5 @@ $MESS['OPEN_SOURCE_ORDER_NO_PAY_SYSTEM_SELECTED'] = 'Не выбрана платежная система'; $MESS['OPEN_SOURCE_ORDER_PROPERTY_REQUIRED'] = 'Свойство #PROPERTY_NAME# обязательное'; $MESS['OPEN_SOURCE_ORDER_PROPERTY_ENUM_INVALID_OPTION'] = 'В свойсте #PROPERTY_NAME# выбрано неверное значение'; -$MESS['OPEN_SOURCE_ORDER_PROPERTY_DATE_WRONG_FORMAT'] = 'Дата в свойстве #PROPERTY_NAME# указана в неверном формате'; \ No newline at end of file +$MESS['OPEN_SOURCE_ORDER_PROPERTY_DATE_WRONG_FORMAT'] = 'Дата в свойстве #PROPERTY_NAME# указана в неверном формате'; +$MESS['OPEN_SOURCE_ORDER_USER_NOT_AUTH'] = 'Для продолжения необходимо авторизироваться'; \ No newline at end of file