fetch(); $entity = HLBT::compileEntity($hlblock); static::$qId = $entity->getDataClass(); } return static::$qId; } public function GetQuality($xml_id) { $class = Order::GetEntityClass(1); $rsData = $class::getList( [ 'select' => array('ID', 'UF_KACHESTVO'), 'filter' => array('UF_XML_ID' => $xml_id) ] ); if ($el = $rsData->fetch()) return $el['UF_KACHESTVO']; return ''; } public function IsQuality($xml_id) { return Order::GetQuality($xml_id) != 'НеГоден'; } function getPropertyByCode($propertyCollection, $code) { foreach ($propertyCollection as $property) if ($property->getField('CODE') == $code) return $property; } public static function NoQualitiesCount($ids) { $class = Order::GetEntityClass(1); $rsData = $class::getList(['select' => ['CNT'], 'runtime' => [new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(*)')], 'filter' => array('UF_XML_ID' => $ids, 'UF_KACHESTVO' => 'НеГоден')])->fetch(); return (int)$rsData['CNT']; } public static function GetOrderCount() { return CSaleBasket::GetList(false, array("FUSER_ID" => CSaleBasket::GetBasketUserID(), "LID" => SITE_ID, "ORDER_ID" => "NULL"), false, false, array("ID"))->SelectedRowsCount(); } static public function GetMarket($parentSect = 0) { $res = ['cats' => [], 'items' => []]; $fil = ['IBLOCK_ID' => 11]; if ($parentSect) $fil = ['SECTION_ID' => $parentSect]; $sect = CIBlockSection::GetList(['SORT' => 'ASC'], $fil, false); $sects = []; while ($sec = $sect->GetNext()) { $res['cats'][$sec['ID']] = $sec['NAME']; $sects[] = $sec['ID']; } $sets = Settings::Get(); $exs = $sets['exceptions']; //'>CATALOG_QUANTITY'=> 0 $rows = CIBlockElement::GetList(['SORT' => 'ASC'], ['IBLOCK_ID' => 11, 'IBLOCK_SECTION_ID' => $sects, 'ACTIVE' => 'Y', 'GLOBAL_ACTIVE' => 'Y', '>CATALOG_QUANTITY' => 0, 'CATALOG_AVAILABLE' => 'Y'], false, false, array('ID', 'NAME', 'DETAIL_PAGE_URL', 'DETAIL_PICTURE', 'PREVIEW_TEXT', 'DETAIL_TEXT', 'XML_ID', 'SECTION_ID', 'CATALOG_GROUP_1')); while ($row = $rows->GetNext()) { $it = []; $it['id'] = $row['ID']; $it['name'] = $row['NAME']; $it['desc'] = $row['PREVIEW_TEXT'] ? $row['PREVIEW_TEXT'] : $row['DETAIL_TEXT']; if ($exs) foreach ($exs as $ex) { $it['name'] = str_replace($ex, '', $it['name']); $it['desc'] = str_replace($ex, '', $it['desc']); } $it['name'] = trim($it['name']); $it['xml_id'] = $row['XML_ID']; $it['quality'] = Order::GetQuality($it['xml_id']); $it['desc'] = trim($it['desc']); $it['url'] = $row['DETAIL_PAGE_URL']; $it['category_id'] = (int)$row['IBLOCK_SECTION_ID']; $it['price'] = (int)$row['CATALOG_PRICE_1']; $cfile = CFile::GetFileArray($row['DETAIL_PICTURE']); $it['image'] = $cfile ? $cfile['SRC'] : ''; $res['items'][$it['id']] = $it; } return $res; } public function GetCart() { CModule::IncludeModule('catalog'); $cart = []; $items = []; $rows = CSaleBasket::GetList(array(), array("FUSER_ID" => CSaleBasket::GetBasketUserID(), "LID" => SITE_ID, "ORDER_ID" => "NULL"), false, false); while ($row = $rows->Fetch()) { $ttepla_item_price = CPrice::GetBasePrice($row['PRODUCT_ID'])['PRICE']; $CCatalogProduct = CCatalogProduct::GetByID($row['PRODUCT_ID']); $item["CATALOG_QUANTITY"] = $CCatalogProduct["QUANTITY"]; $item['num_id'] = $row['ID']; $item['id'] = $row['PRODUCT_ID']; $item['name'] = $row['NAME']; // $item['price'] = (int)$row['PRICE']; $item['price'] = $ttepla_item_price; $item['qty'] = (int)$row['QUANTITY']; $item['url'] = $row['DETAIL_PAGE_URL']; // $item['sum'] = $item['price']*$item['qty']; $item['sum'] = $ttepla_item_price * $item['qty']; $item['MEASURE_NAME'] = $row["MEASURE_NAME"]; $res = CIBlockElement::GetList(array(), ['ID' => $item['id']])->GetNext(); if ($res) { $cfile = CFile::GetFileArray($res['DETAIL_PICTURE']); $item['img'] = $cfile ? $cfile['SRC'] : '/local/images/no-image.png'; } $total += $item['sum']; $qty += $item['qty']; $items[] = $item; } $cart['items'] = $items; $cart['total'] = $total; $cart['qty'] = $qty; return $cart; } public function CreateOrder($cart, $name, $email, $phone, $paysystem) { global $USER; $user_id = $USER->GetID(); $isAuth = 1; if (!$user_id) { $isAuth = 0; $sql = CUser::GetList(($by = "id"), ($order = "desc"), ["EMAIL" => $email]); if ($sql->NavNext(true, "f_")) $user_id = $f_ID; if (!$user_id) $user_id = 2; //анонимный пользователь $USER->Authorize($user_id); } $FUSER_ID = CSaleUser::GetList(array('USER_ID' => $user_id)); if (!$FUSER_ID['ID']) // если покупателя нет - создаем его $FUSER_ID = CSaleUser::_Add(array("USER_ID" => $user_id)); $FUSER_ID = $FUSER_ID['ID']; $siteId = Context::getCurrent()->getSite(); $order = Bitrix\Sale\Order::create($siteId, $user_id); $basket = Basket::loadItemsForFUser(\Bitrix\Sale\Fuser::getId(), $siteId); ///////////// // AddMessage2Log(print_r($basket, true)); // AddMessage2Log(print_r($cart, true)); // foreach($basket as $item){ // $product_id = $item->getField('PRODUCT_ID'); // if($product_id == 14484){ // $item->setField('PRICE', 15); // $item->setField('BASE_PRICE', 15); // $item->setField('CUSTOM_PRICE', "Y"); // } // } ///////////// $order->setBasket($basket); $shipmentCollection = $order->getShipmentCollection(); $shipment = $shipmentCollection->createItem(); $service = Delivery\Services\Manager::getById(Delivery\Services\EmptyDeliveryService::getEmptyDeliveryServiceId()); $shipment->setFields(array('DELIVERY_ID' => $service['ID'], 'DELIVERY_NAME' => $service['NAME'])); $shipmentItemCollection = $shipment->getShipmentItemCollection(); //$shipmentItem = $shipmentItemCollection->createItem($item); //$shipmentItem->setQuantity($item->getQuantity()); $paymentCollection = $order->getPaymentCollection(); $payment = $paymentCollection->createItem(); $paySystemService = PaySystem\Manager::getObjectById($paysystem); $payment->setFields(array( 'PAY_SYSTEM_ID' => $paySystemService->getField("PAY_SYSTEM_ID"), 'PAY_SYSTEM_NAME' => $paySystemService->getField("NAME"), )); $order->setPersonTypeId(1); $order->setField('CURRENCY', "RUB"); $order->setField('CANCELED', "N"); $order->setField('STATUS_ID', "N"); $order->setField('LID', $siteId); //$order->setField('PRODUCT_PROVIDER_CLASS', 'CCatalogProductProvider'); //$order->setField('USER_DESCRIPTION', 'ФИО покупателя: ' . $name . ', телефон: ' . $phone . ', E-mail: ' . $email); $order->setField('COMMENTS', 'ФИО покупателя: ' . $name . ', телефон: ' . $phone . ', E-mail: ' . $email); $propertyCollection = $order->getPropertyCollection(); $prop = Order::getPropertyByCode($propertyCollection, 'NAME'); $prop->setValue($name); $prop = Order::getPropertyByCode($propertyCollection, 'EMAIL'); $prop->setValue($email); $prop = Order::getPropertyByCode($propertyCollection, 'PHONE'); $prop->setValue($phone); $order->doFinalAction(true); $order->save(); if (!$isAuth) $USER->Logout(); $oNum = $order->GetId(); if (!$oNum) return null; CSaleOrder::Update($order->GetId(), []); return ['order_id' => $oNum, 'paytext' => $res]; } // public function Test() // { // var_dump(SITE_ID); // var_dump(Context::getCurrent()->getSite()); // } };