public static function chStatusNew($entity) { try { $fields = $entity->getFields(); self::$values = $fields->getValues(); $old_values = $fields->getOriginalValues(); self::$o_erip = new \Dm\Erip(); self::$opt_status = \Bitrix\Main\Config\Option::get(self::$module_id, "order_status_code_erip"); self::$opt_payment = \Bitrix\Main\Config\Option::get(self::$module_id, "payment_system_id"); //var_dump(self::$opt_status == self::$values["STATUS_ID"]); //var_dump($old_values["STATUS_ID"] != self::$values["STATUS_ID"]); //var_dump(self::$values["PAY_SYSTEM_ID"] == self::$opt_payment); //die; if (self::$opt_status == self::$values["STATUS_ID"] && $old_values["STATUS_ID"] != self::$values["STATUS_ID"] && self::$values["PAY_SYSTEM_ID"] == self::$opt_payment) { static::setTehnicalInfo(); static::setUserInfo(); static::setMoneyInfo(); $r = self::$o_erip->submit(); self::$o_response = json_decode($r); if (isset(self::$o_response->errors)) { throw new \Exception(self::$o_response->message); } if (\Bitrix\Sale\Internals\OrderTable::update(self::$values["ID"], array("COMMENTS" => "status: " . self::$o_response->transaction->status . "\n" . "transaction_id: " . self::$o_response->transaction->transaction_id . "\n" . "order_id: " . self::$o_response->transaction->order_id . "\n" . "account_number: " . self::$o_response->transaction->erip->account_number . "\n"))) { static::sendMail(); } return true; } } catch (Exception $e) { $GLOBALS["APPLICATION"]->ThrowException($e->getMessage()); return false; } }
public static function chStatusNew($entity) { if ($GLOBALS["STOP_ERIP_HANDLER"] === true) { return true; } //отмена запуска обработчика $GLOBALS["STOP_ERIP_HANDLER"] = true; try { $fields = $entity->getFields(); self::$values = $fields->getValues(); $old_values = $fields->getOriginalValues(); self::$o_erip = new \Dm\Erip(); self::$opt_status = \Bitrix\Main\Config\Option::get(self::$module_id, "order_status_code_erip"); self::$opt_payment = \Bitrix\Main\Config\Option::get(self::$module_id, "payment_system_id"); if (self::$opt_status == self::$values["STATUS_ID"] && $old_values["STATUS_ID"] != self::$values["STATUS_ID"] && self::$values["PAY_SYSTEM_ID"] == self::$opt_payment) { self::set_and_send(); if (\Bitrix\Sale\Internals\OrderTable::update(self::$values["ID"], array("COMMENTS" => "status: " . self::$o_response->transaction->status . "\n" . "transaction_id: " . self::$o_response->transaction->transaction_id . "\n" . "order_id: " . self::$o_response->transaction->order_id . "\n" . "account_number: " . self::$o_response->transaction->erip->account_number . "\n"))) { static::sendMail(); } return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS); } } catch (Exception $e) { $error = new \Bitrix\Sale\ResultError($e->getMessage(), $values['ID']); return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR, array('ERROR' => $error), 'sale'); } }
public function filter() { \Bitrix\Main\Loader::includeModule('sale'); $daysDontBuy = $this->getFieldValue('DAYS_DONT_BUY'); if (!is_numeric($daysDontBuy)) { $daysDontBuy = 90; } $dateFrom = new \Bitrix\Main\Type\DateTime(); $dateTo = new \Bitrix\Main\Type\DateTime(); $dateFrom->setTime(0, 0, 0)->add('-' . $daysDontBuy . ' days'); $dateTo->setTime(0, 0, 0)->add('1 days')->add('-' . $daysDontBuy . ' days'); if ($this->isRunForOldData()) { $filter = array('<MAX_DATE_INSERT' => $dateTo->format(\Bitrix\Main\UserFieldTable::MULTIPLE_DATETIME_FORMAT)); } else { $filter = array('>MAX_DATE_INSERT' => $dateFrom->format(\Bitrix\Main\UserFieldTable::MULTIPLE_DATETIME_FORMAT), '<MAX_DATE_INSERT' => $dateTo->format(\Bitrix\Main\UserFieldTable::MULTIPLE_DATETIME_FORMAT)); } $filter = $filter + array('=LID' => $this->getSiteId()); $userListDb = \Bitrix\Sale\Internals\OrderTable::getList(array('select' => array('BUYER_USER_ID' => 'USER.ID', 'EMAIL' => 'USER.EMAIL', 'BUYER_USER_NAME' => 'USER.NAME'), 'filter' => $filter, 'runtime' => array(new \Bitrix\Main\Entity\ExpressionField('MAX_DATE_INSERT', 'MAX(%s)', 'DATE_INSERT')), 'order' => array('USER_ID' => 'ASC'))); if ($userListDb->getSelectedRowsCount() > 0) { $userListDb->addFetchDataModifier(array($this, 'getFetchDataModifier')); $this->recipient = $userListDb; return true; } else { return false; } }
/** * @return array */ public static function getAllFields() { static $fields = null; if ($fields == null) { $fields = array_keys(Internals\OrderTable::getMap()); } return $fields; }
/** * @return array */ public static function getAllFields() { static $fields = null; if ($fields == null) { $map = Internals\OrderTable::getMap(); foreach ($map as $key => $value) { if (is_array($value)) { $fields[] = $key; } elseif ($value instanceof Entity\ScalarField) { $fields[] = $value->getName(); } } } return $fields; }
public static function getFilterCounter($filter) { if (!is_array($filter)) { $filter = array(); } if (empty($filter)) { return self::getAllCounter(); } $filter['ORDER_DISCOUNT_DATA.ID'] = null; $countQuery = new Main\Entity\Query(Sale\Internals\OrderTable::getEntity()); $countQuery->addSelect(new Main\Entity\ExpressionField('CNT', 'COUNT(1)')); $countQuery->setFilter($filter); $totalCount = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch(); return (int) $totalCount['CNT']; }
/** @return \CDBResult */ public function getData() { $runtime = array(); $filter = array(); if ($this->getFieldValue('LID')) { $filter['=LID'] = $this->getFieldValue('LID', null); } if ($this->getFieldValue('ID')) { $filter['=ID'] = $this->getFieldValue('ID', 0); } if ($this->getFieldValue('USER_ID')) { $filter['=USER_ID'] = $this->getFieldValue('USER_ID', 0); } if ($this->getFieldValue('BASKET_PRODUCT_ID')) { $filter['=BASKET.PRODUCT_ID'] = $this->getFieldValue('BASKET_PRODUCT_ID', 0); $runtime['BASKET'] = array('data_type' => 'Bitrix\\Sale\\Internals\\Basket', 'reference' => array('=this.ID' => 'ref.ORDER_ID')); } $resultDb = \Bitrix\Sale\Internals\OrderTable::getList(array('select' => array('USER_ID', 'NAME' => 'USER.NAME', 'EMAIL' => 'USER.EMAIL'), 'filter' => $filter, 'runtime' => $runtime, 'group' => array('USER_ID', 'NAME', 'EMAIL'), 'order' => array('USER_ID' => 'ASC'))); return new \CDBResult($resultDb); }
echo $arResult["ORDER_BASKET"]["ORDER_ID"]; ?> '); </script> <?php echo GetMessage("SOA_TEMPL_PAY_LINK", array("#LINK#" => $arParams["PATH_TO_PAYMENT"] . "?ORDER_ID=" . $arResult["ORDER_BASKET"]["ORDER_ID"])); ?> <?php } else { $service = \Bitrix\Sale\PaySystem\Manager::getObjectById($arResult['PAY_SYSTEM_ID']); if ($service) { $orderId = $arResult['ORDER_ID']; /** @var \Bitrix\Sale\Order $order */ $order = \Bitrix\Sale\Order::load($orderId); if ($order === null) { $data = \Bitrix\Sale\Internals\OrderTable::getRow(array('select' => array('ID'), 'filter' => array('ACCOUNT_NUMBER' => $orderId))); $order = \Bitrix\Sale\Order::load($data['ID']); } /** @var \Bitrix\Sale\PaymentCollection $paymentCollection */ $paymentCollection = $order->getPaymentCollection(); /** @var \Bitrix\Sale\Payment $payment */ foreach ($paymentCollection as $payment) { if (!$payment->isInner()) { $context = \Bitrix\Main\Application::getInstance()->getContext(); $service->initiatePay($payment, $context->getRequest()); break; } } } else { echo '<span style="color:red;">' . GetMessage("SOA_TEMPL_ORDER_PS_ERROR") . '</span>'; }
/** * The agent function. Moves reserved quantity back to the quantity field for each product * for orders which were placed earlier than specific date * * @return agent name string */ public static function ClearProductReservedQuantity() { global $DB, $USER; if (!is_object($USER)) { $USER = new CUser(); } $days_ago = (int) COption::GetOptionString("sale", "product_reserve_clear_period"); if ($days_ago > 0) { $shipmentList = array(); $date = new \Bitrix\Main\Type\DateTime(); $filter = array('filter' => array("<=DATE_INSERT" => $date->add('-' . $days_ago . ' day'), "=SHIPMENT.RESERVED" => "Y", "=SHIPMENT.DEDUCTED" => "N", "=SHIPMENT.MARKED" => "N", "=SHIPMENT.ALLOW_DELIVERY" => "N", "=PAYED" => "N", "=CANCELED" => "N"), 'select' => array("ID", "SHIPMENT_ID" => "SHIPMENT.ID", "SHIPMENT_RESERVED" => "SHIPMENT.RESERVED", "SHIPMENT_DEDUCTED" => "SHIPMENT.DEDUCTED", "DATE_INSERT", "PAYED", "CANCELED", "MARKED")); $res = \Bitrix\Sale\Internals\OrderTable::getList($filter); while ($data = $res->fetch()) { if (!array_key_exists($data['ID'], $shipmentList)) { $shipmentList[$data['ID']] = array(); } if (in_array($data['SHIPMENT_ID'], $shipmentList[$data['ID']])) { continue; } $shipmentList[$data['ID']][] = $data['SHIPMENT_ID']; } if (!empty($shipmentList)) { foreach ($shipmentList as $orderId => $shipmentData) { /** @var Sale\Order $order */ $order = Sale\Order::load($orderId); $orderSaved = false; $errors = array(); try { /** @var Sale\ShipmentCollection $shipmentCollection */ if ($shipmentCollection = $order->getShipmentCollection()) { foreach ($shipmentData as $shipmentId) { /** @var Sale\Shipment $shipment */ if ($shipment = $shipmentCollection->getItemById($shipmentId)) { $r = $shipment->tryUnreserve(); if (!$r->isSuccess()) { if (!$shipment->isMarked()) { $shipment->setField('MARKED', 'Y'); if (is_array($r->getErrorMessages())) { $oldErrorText = $shipment->getField('REASON_MARKED'); foreach ($r->getErrorMessages() as $error) { $oldErrorText .= (strval($oldErrorText) != '' ? "\n" : "") . $error; } $shipment->setField('REASON_MARKED', $oldErrorText); } } } } } } $r = $order->save(); if ($r->isSuccess()) { $orderSaved = true; } else { $errors = $r->getErrorMessages(); } } catch (Exception $e) { $errors[] = $e->getMessage(); } if (!$orderSaved) { if (!empty($errors)) { $oldErrorText = $order->getField('REASON_MARKED'); foreach ($errors as $error) { $oldErrorText .= (strval($oldErrorText) != '' ? "\n" : "") . $error; } Sale\Internals\OrderTable::update($order->getId(), array("MARKED" => "Y", "REASON_MARKED" => $oldErrorText)); } } } } } return "CSaleOrder::ClearProductReservedQuantity();"; }
/** * Return order locked status. * * @param int $id Order id. * @return Result * @throws Main\ArgumentException */ public static function getLockedStatus($id) { $result = new Result(); $res = Internals\OrderTable::getList(array('filter' => array('=ID' => $id), 'select' => array('LOCKED_BY', 'LOCK_STATUS', 'DATE_LOCK'))); if ($data = $res->fetch()) { $result->addData(array('LOCKED_BY' => $data['LOCKED_BY'], 'LOCK_STATUS' => $data['LOCK_STATUS'], 'DATE_LOCK' => $data['DATE_LOCK'])); } return $result; }
/** * @param array $filter * * @return Main\DB\Result * @throws Main\ArgumentException */ public static function getList(array $filter = array()) { return Internals\OrderTable::getList($filter); }
/** * @return array */ protected static function getSelectFields() { $fields = array_keys(OrderTable::getEntity()->getScalarFields()); return array_merge($fields, array('DATE_INSERT_FORMAT', 'DATE_UPDATE_SHORT', 'DATE_STATUS_SHORT', 'DATE_CANCELED_SHORT', 'BY_RECOMMENDATION', 'LOCK_STATUS', 'LOCK_USER_NAME', 'DATE_INSERT_FORMAT', "RESPONSIBLE_ID", "RESPONSIBLE_LOGIN", "RESPONSIBLE_NAME", "RESPONSIBLE_LAST_NAME", "RESPONSIBLE_SECOND_NAME", "RESPONSIBLE_EMAIL", "RESPONSIBLE_WORK_POSITION", "RESPONSIBLE_PERSONAL_PHOTO", "RESPONSIBLE_GROUP_ID", "PAY_SYSTEM_ID", "DELIVERY_ID", "DEDUCTED", "RESERVED", "PRICE_DELIVERY", "ALLOW_DELIVERY", "DATE_ALLOW_DELIVERY", "EMP_ALLOW_DELIVERY_ID", "DELIVERY_DOC_NUM", "DELIVERY_DOC_DATE", "PAYED", "DATE_PAYED", "EMP_PAYED_ID", "STATUS_ID", "DATE_STATUS", "EMP_STATUS_ID", "DATE_INSERT_FORMAT", "USER_LOGIN", "USER_NAME", "USER_LAST_NAME", "USER_EMAIL", "DATE_PAY_BEFORE", "DATE_BILL", "ACCOUNT_NUMBER", "TRACKING_NUMBER")); }
public static function takeOutOrdersToCorrespondentTable() { $platformId = \Bitrix\Sale\TradingPlatform\YandexMarket::getInstance()->getId(); if (intval($platformId) <= 0) { return ""; } $conn = \Bitrix\Main\Application::getConnection(); $helper = $conn->getSqlHelper(); $correspondence = $conn->query('SELECT ID FROM ' . $helper->quote(\Bitrix\Sale\TradingPlatform\OrderTable::getTableName()) . ' WHERE ' . $helper->quote('TRADING_PLATFORM_ID') . '=' . $platformId); //check if we already tried to convert if ($correspondence->fetch()) { return ""; } if ($conn->getType() == "mssql") { $lenOpName = "LEN"; } else { $lenOpName = "LENGTH"; } if ($conn->getType() == "oracle") { $right = 'SUBSTR(XML_ID, -(' . $lenOpName . '(XML_ID)-' . strlen(self::XML_ID_PREFIX) . '))'; } else { $right = 'RIGHT(XML_ID, ' . $lenOpName . '(XML_ID)-' . strlen(self::XML_ID_PREFIX) . ')'; } //take out correspondence to $sql = 'INSERT INTO ' . \Bitrix\Sale\TradingPlatform\OrderTable::getTableName() . ' (ORDER_ID, EXTERNAL_ORDER_ID, TRADING_PLATFORM_ID) SELECT ID, ' . $right . ', ' . $platformId . ' FROM ' . \Bitrix\Sale\Internals\OrderTable::getTableName() . ' WHERE XML_ID LIKE ' . "'" . self::XML_ID_PREFIX . "%'"; try { $conn->queryExecute($sql); } catch (\Bitrix\Main\DB\SqlQueryException $e) { CEventLog::Add(array("SEVERITY" => "ERROR", "AUDIT_TYPE_ID" => "YMARKET_XML_ID_CONVERT_INSERT_ERROR", "MODULE_ID" => "sale", "ITEM_ID" => "YMARKET", "DESCRIPTION" => __FILE__ . ': ' . $e->getMessage())); } return ""; }
/** * Perform reading main data from database, no cache is used * @return void */ protected function obtainDataOrders() { $select = array('ID', 'LID', 'PERSON_TYPE_ID', 'PAYED', 'DATE_PAYED', 'EMP_PAYED_ID', 'CANCELED', 'DATE_CANCELED', 'EMP_CANCELED_ID', 'REASON_CANCELED', 'MARKED', 'DATE_MARKED', 'EMP_MARKED_ID', 'REASON_MARKED', 'STATUS_ID', 'DATE_STATUS', 'PAY_VOUCHER_NUM', 'PAY_VOUCHER_DATE', 'EMP_STATUS_ID', 'PRICE_DELIVERY', 'ALLOW_DELIVERY', 'DATE_ALLOW_DELIVERY', 'EMP_ALLOW_DELIVERY_ID', 'DEDUCTED', 'DATE_DEDUCTED', 'EMP_DEDUCTED_ID', 'REASON_UNDO_DEDUCTED', 'RESERVED', 'PRICE', 'CURRENCY', 'DISCOUNT_VALUE', 'SUM_PAID', 'USER_ID', 'PAY_SYSTEM_ID', 'DELIVERY_ID', 'DATE_INSERT', 'DATE_UPDATE', 'USER_DESCRIPTION', 'ADDITIONAL_INFO', 'COMMENTS', 'TAX_VALUE', 'STAT_GID', 'RECURRING_ID', 'RECOUNT_FLAG', 'DELIVERY_DOC_NUM', 'DELIVERY_DOC_DATE', 'STORE_ID', 'ORDER_TOPIC', 'RESPONSIBLE_ID', 'DATE_PAY_BEFORE', 'DATE_BILL', 'ACCOUNT_NUMBER', 'TRACKING_NUMBER', 'XML_ID'); $usePageNavigation = true; $navyParams = array(); $navyParams = \CDBResult::GetNavParams(); if ($navyParams['SHOW_ALL']) { $usePageNavigation = false; } else { $navyParams['PAGEN'] = (int) $navyParams['PAGEN']; $navyParams['SIZEN'] = (int) $navyParams['SIZEN']; } if (isset($this->arParams["ORDERS_PER_PAGE"]) && intval($this->arParams["ORDERS_PER_PAGE"]) > 0) { $navyParams['SIZEN'] = $this->arParams["ORDERS_PER_PAGE"]; } if (isset($_REQUEST['show_all']) && $_REQUEST['show_all'] == "Y") { $usePageNavigation = false; } $getListParams = array('order' => array($this->sortBy => $this->sortOrder), 'filter' => $this->filter, 'select' => $select); if ($usePageNavigation) { $getListParams['limit'] = $navyParams['SIZEN']; $getListParams['offset'] = $navyParams['SIZEN'] * ($navyParams['PAGEN'] - 1); } $totalPages = 0; if ($usePageNavigation) { $countQuery = new \Bitrix\Main\Entity\Query(\Bitrix\Sale\Internals\OrderTable::getEntity()); $countQuery->addSelect(new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(1)')); $countQuery->setFilter($getListParams['filter']); $totalCount = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch(); unset($countQuery); $totalCount = (int) $totalCount['CNT']; if ($totalCount > 0) { $totalPages = ceil($totalCount / $navyParams['SIZEN']); if ($navyParams['PAGEN'] > $totalPages) { $navyParams['PAGEN'] = $totalPages; } $getListParams['limit'] = $navyParams['SIZEN']; $getListParams['offset'] = $navyParams['SIZEN'] * ($navyParams['PAGEN'] - 1); } else { $navyParams['PAGEN'] = 1; $getListParams['limit'] = $navyParams['SIZEN']; $getListParams['offset'] = 0; } } $this->dbQueryResult['ORDERS'] = new \CDBResult(\Bitrix\Sale\Internals\OrderTable::getList($getListParams)); if ($usePageNavigation) { $this->dbQueryResult['ORDERS']->NavStart($getListParams['limit'], $navyParams['SHOW_ALL'], $navyParams['PAGEN']); $this->dbQueryResult['ORDERS']->NavRecordCount = $totalCount; $this->dbQueryResult['ORDERS']->NavPageCount = $totalPages; $this->dbQueryResult['ORDERS']->NavPageNomer = $navyParams['PAGEN']; } else { $this->dbQueryResult['ORDERS']->NavStart($this->arParams["ORDERS_PER_PAGE"], false); } if (empty($this->dbQueryResult['ORDERS'])) { return; } while ($arOrder = $this->dbQueryResult['ORDERS']->GetNext()) { $arOBasket = array(); $dbBasket = CSaleBasket::GetList(array('NAME' => 'asc'), array("ORDER_ID" => $arOrder["ID"]), false, false, array('*')); while ($arBasket = $dbBasket->Fetch()) { if (CSaleBasketHelper::isSetItem($arBasket)) { continue; } $arOBasket[$arBasket['ID']] = $arBasket; } $arOShipment = array(); $dbShipment = \Bitrix\Sale\Internals\ShipmentTable::getList(array('select' => array('DELIVERY_NAME', 'SYSTEM', 'DELIVERY_ID'), 'filter' => array('ORDER_ID' => $arOrder['ID']))); while ($arShipment = $dbShipment->fetch()) { if ($arShipment['SYSTEM'] == 'Y') { continue; } $arOShipment[] = $arShipment; } $dbPayment = \Bitrix\Sale\Internals\PaymentTable::getList(array('select' => array('PAY_SYSTEM_NAME', 'PAY_SYSTEM_ID'), 'filter' => array('ORDER_ID' => $arOrder['ID']))); $arOPayment = array(); while ($arPayment = $dbPayment->fetch()) { $arOPayment[] = $arPayment; } $this->dbResult['ORDERS'][] = array("ORDER" => $arOrder, "BASKET_ITEMS" => $arOBasket, "SHIPMENT" => $arOShipment, "PAYMENT" => $arOPayment); } }
function CalculateAffiliate($affiliate, $dateFrom = false, $dateTo = false, $datePlanFrom = false, $datePlanTo = false) { global $DB; // Prepare function params - affiliate $arAffiliate = CSaleAffiliate::CheckAffiliateFunc($affiliate); if (!$arAffiliate) { return False; } $db_events = GetModuleEvents("sale", "OnBeforeAffiliateCalculate"); while ($arEvent = $db_events->Fetch()) { if (ExecuteModuleEventEx($arEvent, array(&$arAffiliate, &$dateFrom, &$dateTo, &$datePlanFrom, &$datePlanTo)) === false) { return false; } } $affiliateID = IntVal($arAffiliate["ID"]); if (!$dateFrom || StrLen($dateFrom) <= 0) { if (StrLen($arAffiliate["LAST_CALCULATE"]) > 0) { $dateFrom = $arAffiliate["LAST_CALCULATE"]; } else { $dateFrom = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), mktime(0, 0, 0, 1, 1, 1990)); } } if (!$dateTo || StrLen($dateTo) <= 0) { $dateTo = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), time() + CTimeZone::GetOffset()); } // Get affiliate plan $arAffiliatePlan = CSaleAffiliate::SetAffiliatePlan($arAffiliate, $datePlanFrom, $datePlanTo); if (!$arAffiliatePlan) { return False; } if ($arAffiliatePlan && !is_array($arAffiliatePlan)) { return true; } // Get affiliate plan params $arPlanSections = array(); $dbPlanSection = CSaleAffiliatePlanSection::GetList(array(), array("PLAN_ID" => $arAffiliate["PLAN_ID"]), false, false, array("ID", "MODULE_ID", "SECTION_ID", "RATE", "RATE_TYPE", "RATE_CURRENCY")); while ($arPlanSection = $dbPlanSection->Fetch()) { $arPlanSections[$arPlanSection["MODULE_ID"] . $arPlanSection["SECTION_ID"]] = $arPlanSection; } // Get affiliate parents $arAffiliateParents = array(); $affiliateParent = IntVal($arAffiliate["AFFILIATE_ID"]); $count = 0; while ($affiliateParent > 0 && $count < 5) { $dbAffiliateParent = CSaleAffiliate::GetList(array(), array("ID" => $affiliateParent, "ACTIVE" => "Y"), false, false, array("ID", "AFFILIATE_ID")); if ($arAffiliateParent = $dbAffiliateParent->Fetch()) { $count++; $arAffiliateParents[] = $affiliateParent; $affiliateParent = IntVal($arAffiliateParent["AFFILIATE_ID"]); } else { $affiliateParent = 0; } } // Get tier if (!array_key_exists("SALE_AFFILIATE_TIER_TMP_CACHE", $GLOBALS)) { $GLOBALS["SALE_AFFILIATE_TIER_TMP_CACHE"] = array(); } if (!array_key_exists($arAffiliate["SITE_ID"], $GLOBALS["SALE_AFFILIATE_TIER_TMP_CACHE"])) { $dbAffiliateTier = CSaleAffiliateTier::GetList(array(), array("SITE_ID" => $arAffiliate["SITE_ID"]), false, false, array("RATE1", "RATE2", "RATE3", "RATE4", "RATE5")); if ($arAffiliateTier = $dbAffiliateTier->Fetch()) { $GLOBALS["SALE_AFFILIATE_TIER_TMP_CACHE"][$arAffiliate["SITE_ID"]] = array(DoubleVal($arAffiliateTier["RATE1"]), DoubleVal($arAffiliateTier["RATE2"]), DoubleVal($arAffiliateTier["RATE3"]), DoubleVal($arAffiliateTier["RATE4"]), DoubleVal($arAffiliateTier["RATE5"])); } else { $GLOBALS["SALE_AFFILIATE_TIER_TMP_CACHE"][$arAffiliate["SITE_ID"]] = array(0, 0, 0, 0, 0); } } // Orders cicle $affiliateSum = 0; $affiliateCurrency = CSaleLang::GetLangCurrency($arAffiliate["SITE_ID"]); $dbOrders = \Bitrix\Sale\Internals\OrderTable::getList(array('filter' => array("=ALLOW_DELIVERY" => 'Y', ">=DATE_ALLOW_DELIVERY" => $dateFrom, "<DATE_ALLOW_DELIVERY" => $dateTo, "=AFFILIATE_ID" => $affiliateID, "=LID" => $arAffiliate["SITE_ID"], "=CANCELED" => 'N'), 'select' => array("ID", "LID", "PRICE_DELIVERY", "PRICE", "CURRENCY", "TAX_VALUE", "AFFILIATE_ID", "BASKET_QUANTITY" => 'BASKET.QUANTITY', "BASKET_PRODUCT_ID" => 'BASKET.PRODUCT_ID', "BASKET_MODULE" => 'BASKET.MODULE', "BASKET_PRICE" => 'BASKET.PRICE', "BASKET_CURRENCY" => 'BASKET.CURRENCY', "BASKET_DISCOUNT_PRICE" => 'BASKET.DISCOUNT_PRICE'), 'order' => array('ID' => 'ASC'))); $fOrderId = ""; while ($arOrder = $dbOrders->fetch()) { $arProductSections = array(); if (!array_key_exists("SALE_PRODUCT_SECTION_CACHE", $GLOBALS)) { $GLOBALS["SALE_PRODUCT_SECTION_CACHE"] = array(); } if (array_key_exists($arOrder["BASKET_MODULE"] . $arOrder["BASKET_PRODUCT_ID"], $GLOBALS["SALE_PRODUCT_SECTION_CACHE"])) { $arProductSections = $GLOBALS["SALE_PRODUCT_SECTION_CACHE"][$arOrder["BASKET_MODULE"] . $arOrder["BASKET_PRODUCT_ID"]]; unset($GLOBALS["SALE_PRODUCT_SECTION_CACHE"][$arOrder["BASKET_MODULE"] . $arOrder["BASKET_PRODUCT_ID"]]); $GLOBALS["SALE_PRODUCT_SECTION_CACHE"] = $GLOBALS["SALE_PRODUCT_SECTION_CACHE"] + array($arOrder["BASKET_MODULE"] . $arOrder["BASKET_PRODUCT_ID"] => $arProductSections); } else { if ($arOrder["BASKET_MODULE"] == "catalog") { CModule::IncludeModule("catalog"); $arSku = CCatalogSku::GetProductInfo($arOrder["BASKET_PRODUCT_ID"]); if ($arSku && count($arSku) > 0) { $elementId = $arSku["ID"]; } else { $elementId = $arOrder["BASKET_PRODUCT_ID"]; } $arProductSections = CCatalogProduct::GetProductSections($elementId); } else { $events = GetModuleEvents("sale", "OnAffiliateGetSections"); if ($arEvent = $events->Fetch()) { $arProductSections = ExecuteModuleEventEx($arEvent, array($arOrder["BASKET_MODULE"], $arOrder["BASKET_PRODUCT_ID"])); } } $GLOBALS["SALE_PRODUCT_SECTION_CACHE"] = $GLOBALS["SALE_PRODUCT_SECTION_CACHE"] + array($arOrder["BASKET_MODULE"] . $arOrder["BASKET_PRODUCT_ID"] => $arProductSections); if (count($GLOBALS["SALE_PRODUCT_SECTION_CACHE"]) > 20) { array_shift($GLOBALS["SALE_PRODUCT_SECTION_CACHE"]); } } $realRate = $arAffiliatePlan["BASE_RATE"]; $realRateType = $arAffiliatePlan["BASE_RATE_TYPE"]; $realRateCurrency = $arAffiliatePlan["BASE_RATE_CURRENCY"]; $coountArProd = count($arProductSections); for ($i = 0; $i < $coountArProd; $i++) { if (array_key_exists($arOrder["BASKET_MODULE"] . $arProductSections[$i], $arPlanSections)) { $realRate = $arPlanSections[$arOrder["BASKET_MODULE"] . $arProductSections[$i]]["RATE"]; $realRateType = $arPlanSections[$arOrder["BASKET_MODULE"] . $arProductSections[$i]]["RATE_TYPE"]; $realRateCurrency = $arPlanSections[$arOrder["BASKET_MODULE"] . $arProductSections[$i]]["RATE_CURRENCY"]; break; } } if ($realRateType == "P") { if ($arOrder["CURRENCY"] != $affiliateCurrency) { if (!array_key_exists("SALE_CONVERT_CURRENCY_CACHE", $GLOBALS)) { $GLOBALS["SALE_CONVERT_CURRENCY_CACHE"] = array(); } if (!array_key_exists($arOrder["CURRENCY"] . "-" . $affiliateCurrency, $GLOBALS["SALE_CONVERT_CURRENCY_CACHE"])) { $GLOBALS["SALE_CONVERT_CURRENCY_CACHE"][$arOrder["CURRENCY"] . "-" . $affiliateCurrency] = CCurrencyRates::GetConvertFactor($arOrder["CURRENCY"], $affiliateCurrency); } if ($fOrderId != $arOrder["ID"]) { $affiliateSum += \Bitrix\Sale\PriceMaths::roundPrecision(($arOrder["PRICE"] - $arOrder["PRICE_DELIVERY"]) * $GLOBALS["SALE_CONVERT_CURRENCY_CACHE"][$arOrder["CURRENCY"] . "-" . $affiliateCurrency] * $realRate / 100); $fOrderId = $arOrder["ID"]; } } else { if ($fOrderId != $arOrder["ID"]) { $affiliateSum += \Bitrix\Sale\PriceMaths::roundPrecision(($arOrder["PRICE"] - $arOrder["PRICE_DELIVERY"]) * $realRate / 100); $fOrderId = $arOrder["ID"]; } } } else { if ($realRateCurrency != $affiliateCurrency) { if (!array_key_exists("SALE_CONVERT_CURRENCY_CACHE", $GLOBALS)) { $GLOBALS["SALE_CONVERT_CURRENCY_CACHE"] = array(); } if (!array_key_exists($realRateCurrency . "-" . $affiliateCurrency, $GLOBALS["SALE_CONVERT_CURRENCY_CACHE"])) { $GLOBALS["SALE_CONVERT_CURRENCY_CACHE"][$realRateCurrency . "-" . $affiliateCurrency] = CCurrencyRates::GetConvertFactor($realRateCurrency, $affiliateCurrency); } $affiliateSum += roundEx($realRate * $GLOBALS["SALE_CONVERT_CURRENCY_CACHE"][$realRateCurrency . "-" . $affiliateCurrency], SALE_VALUE_PRECISION); } else { $affiliateSum += roundEx($realRate, SALE_VALUE_PRECISION); } } } $arFields = array("=PENDING_SUM" => "PENDING_SUM + " . $affiliateSum, "LAST_CALCULATE" => $dateTo); $res = CSaleAffiliate::Update($affiliateID, $arFields); if (!$res) { return False; } if ($affiliateSum > 0) { $cnt = min(count($arAffiliateParents), count($GLOBALS["SALE_AFFILIATE_TIER_TMP_CACHE"][$arAffiliate["SITE_ID"]])); for ($i = 0; $i < $cnt; $i++) { $affiliateSumTmp = roundEx($affiliateSum * $GLOBALS["SALE_AFFILIATE_TIER_TMP_CACHE"][$arAffiliate["SITE_ID"]][$i] / 100, SALE_VALUE_PRECISION); $arFields = array("=PENDING_SUM" => "PENDING_SUM + " . $affiliateSumTmp); CSaleAffiliate::Update($arAffiliateParents[$i], $arFields); } } $events = GetModuleEvents("sale", "OnAfterAffiliateCalculate"); while ($arEvent = $events->Fetch()) { ExecuteModuleEventEx($arEvent, array($affiliateID)); } return True; }
protected function saveCommentsAction() { if (!isset($this->request['orderId']) || intval($this->request['orderId']) <= 0) { throw new SystemException("Wrong order id!"); } if (!isset($this->request['comments'])) { throw new SystemException("Can't find the comments content!"); } $res = Sale\Internals\OrderTable::update($this->request['orderId'], array("COMMENTS" => $this->request['comments'])); if (!$res->isSuccess()) { $this->addResultError(join("\n", $res->getErrorMessages())); } $CBXSanitizer = new \CBXSanitizer(); $CBXSanitizer->SetLevel(\CBXSanitizer::SECURE_LEVEL_MIDDLE); $this->addResultData("COMMENTS", $CBXSanitizer->SanitizeHtml($this->request['comments'])); }
/** * <p>Метод удаляет статус заказа с кодом ID. Если в базе есть заказы, находящиеся в этом статусе, то этот статус удалить нельзя. Метод динамичный.</p> * * * @param string $ID Код статуса заказа. </htm * * @return bool <p>Возвращается <i>true</i> в случае успешного удаления и <i>false</i> - в * противном случае.</p> <br><br> * * @static * @link http://dev.1c-bitrix.ru/api_help/sale/classes/csalestatus/csalestatus__delete.11104aab.php * @author Bitrix */ public static function Delete($statusId) { if (!$statusId) { return false; } global $DB, $APPLICATION; $statusId = $DB->ForSql($statusId, 2); if (OrderTable::getList(array('filter' => array('=STATUS_ID' => $statusId), 'limit' => 1))->fetch()) { $APPLICATION->ThrowException(Loc::getMessage("SKGS_ERROR_DELETE"), "ERROR_DELETE_STATUS_TO_ORDER"); return false; } foreach (GetModuleEvents("sale", "OnBeforeStatusDelete", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($statusId)) === false) { return false; } } foreach (GetModuleEvents("sale", "OnStatusDelete", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($statusId)); } StatusLangTable::deleteByStatus($statusId); StatusGroupTaskTable::deleteByStatus($statusId); return StatusTable::delete($statusId)->isSuccess(); }
/* CommerceML format. Every item in shopping cart should have the following */ /* properties: */ /* - catalog XML_ID (with mnemonic code CATALOG.XML_ID) */ /* - product XML_ID (with mnemonic code PRODUCT.XML_ID). */ /****************************************************************************/ $SALER_COMPANY_XML_ID = "1"; IncludeModuleLangFile(__FILE__); if (!isset($arFilter) || !is_array($arFilter)) { die("Wrong use 1"); } $filter = array('filter' => $arFilter, 'select' => array("ID", "LID", "PERSON_TYPE_ID", "PAYED", "DATE_PAYED", "EMP_PAYED_ID", "CANCELED", "DATE_CANCELED", "EMP_CANCELED_ID", "REASON_CANCELED", "STATUS_ID", "DATE_STATUS", "PAY_VOUCHER_NUM", "PAY_VOUCHER_DATE", "EMP_STATUS_ID", "PRICE_DELIVERY", "ALLOW_DELIVERY", "DATE_ALLOW_DELIVERY", "EMP_ALLOW_DELIVERY_ID", "PRICE", "CURRENCY", "DISCOUNT_VALUE", "SUM_PAID", "USER_ID", "PAY_SYSTEM_ID", "DELIVERY_ID", "DATE_INSERT", "DATE_INSERT_FORMAT", "DATE_UPDATE", "USER_DESCRIPTION", "ADDITIONAL_INFO", 'PS_STATUS' => 'PAYMENT.PS_STATUS', 'PS_STATUS_CODE' => 'PAYMENT.PS_STATUS_CODE', 'PS_STATUS_DESCRIPTION' => 'PAYMENT.PS_STATUS_DESCRIPTION', 'PS_STATUS_MESSAGE' => 'PAYMENT.PS_STATUS_MESSAGE', 'PS_SUM' => 'PAYMENT.PS_SUM', 'PS_CURRENCY' => 'PAYMENT.PS_CURRENCY', 'PS_RESPONSE_DATE' => 'PAYMENT.PS_RESPONSE_DATE', "COMMENTS", "TAX_VALUE", "STAT_GID", "RECURRING_ID"), 'runtime' => $runtimeFields); if (!empty($by)) { $order = !empty($order) && $order == "DESC" ? "DESC" : "ASC"; $filter['order'] = array($by => $order); } $dbOrderList = new CDBResult(\Bitrix\Sale\Internals\OrderTable::getList($filter)); ob_start(); echo "<" . "?xml version=\"1.0\" encoding=\"" . LANG_CHARSET . "\"?" . ">\n"; echo "<BizTalk xmlns=\"urn:schemas-biztalk-org:biztalk/biztalk-0.81.xml\"><Route><From locationID=\"\" locationType=\"\" process=\"\" path=\"\" handle=\"\"/><To locationID=\"\" locationType=\"\" process=\"\" path=\"\" handle=\"\"/></Route><Body>\n"; echo "\t<" . GetMessage("CommerceInfo") . " xmlns=\"urn:CommerceML\">\n"; $arContra = array(); while ($dbOrderList->NavNext(true, "f_")) { echo "\t\t<" . GetMessage("Document") . " " . GetMessage("Operation") . "=\"Order\" " . GetMessage("NumberDoc") . "=\"" . $f_ID . "\" "; echo "" . GetMessage("DateDoc") . "=\"" . CDatabase::FormatDate($f_DATE_INSERT, CLang::GetDateFormat("FULL", LANG), "Y-M-D") . "\" " . GetMessage("TimeDoc") . "=\"" . CDatabase::FormatDate($f_DATE_INSERT, CLang::GetDateFormat("FULL", LANG), "HH:MI:SS") . "\" " . GetMessage("PaymentDate") . "=\"\" "; echo "" . GetMessage("Sum") . "=\"" . $f_PRICE . "\" " . GetMessage("Comment") . "=\"\" " . GetMessage("Currency") . "=\"" . $f_CURRENCY . "\">\n"; echo "\t\t\t<" . GetMessage("CompanyInDocument") . " " . GetMessage("Role") . "=\"Saler\" " . GetMessage("Company") . "=\"" . $SALER_COMPANY_XML_ID . "\"/>\n"; echo "\t\t\t<" . GetMessage("CompanyInDocument") . " " . GetMessage("Role") . "=\"Buyer\" " . GetMessage("Company") . "=\"BC" . $f_USER_ID . "\"/>\n"; $dbOrderTax = CSaleOrderTax::GetList(array(), array("ORDER_ID" => $f_ID), false, false, array("ID", "TAX_NAME", "VALUE", "VALUE_MONEY", "CODE", "IS_IN_PRICE")); while ($arOrderTax = $dbOrderTax->Fetch()) { echo "\t\t\t<" . GetMessage("TaxSum") . " " . GetMessage("Tax") . "=\"" . htmlspecialcharsbx($arOrderTax["TAX_NAME"]) . "\" " . GetMessage("TaxRate") . "=\"" . htmlspecialcharsbx($arOrderTax["VALUE"]) . "\" " . GetMessage("Sum") . "=\"" . htmlspecialcharsbx($arOrderTax["VALUE_MONEY"]) . "\" " . GetMessage("IncludedInSum") . "=\"" . ($arOrderTax["IS_IN_PRICE"] == "Y" ? 1 : 0) . "\"/>\n"; }
private static function get($codeName, $order, $payment, $shipment) { static $cache = array(); if (is_numeric($order)) { $order = ($v = $cache[$order]) ? $v : OrderTable::getById($order)->fetch(); } elseif ($order instanceof Order) { $order = $order->getFieldValues(); } if (is_array($order)) { $cache[$order['ID']] = $order; } else { return null; } $result = null; list($entity, $item) = self::getMap($codeName, $order['PERSON_TYPE_ID']); switch ($entity) { case 'VALUE': $result = $item; break; case 'ORDER': $result = $order[$item]; break; case 'PAYMENT': if ($payment) { $result = $payment[$item]; } break; case 'SHIPMENT': if ($shipment) { $result = $shipment[$item]; } break; case 'PROPERTY': $property = OrderPropsValueTable::getList(array('select' => array('VALUE'), 'filter' => array('ORDER_ID' => $order['ID'], 'ORDER_PROPS_ID' => $item), 'limit' => 1))->fetch(); if ($property) { $result = $property['VALUE']; } break; case 'COMPANY': $companyId = null; if ($payment) { $companyId = $payment['COMPANY_ID']; } elseif ($shipment) { $companyId = $shipment['COMPANY_ID']; } if ($companyId) { if (substr($item, 0, 3) == 'UF_') { global $USER_FIELD_MANAGER; if ($value = $USER_FIELD_MANAGER->GetUserFieldValue(CompanyTable::getUfId(), $item, $companyId)) { $result = $value; } } else { if ($company = CompanyTable::getById($companyId)->fetch()) { $result = $company[$item]; } } } break; case 'USER': global $USER; if (($userId = $order['USER_ID']) && ($user = $USER->GetByID($userId)->Fetch())) { $result = $user[$item]; } break; } return $result; }
/** * Clear coupon storage for order. * * @param int $order Order id. * @return bool */ public static function clearByOrder($order) { if (!self::isSuccess()) { return false; } $order = (int) $order; if ($order <= 0) { return false; } $userId = 0; $orderIterator = Internals\OrderTable::getList(array('select' => array('ID', 'USER_ID'), 'filter' => array('=ID' => $order))); if ($orderData = $orderIterator->fetch()) { $userId = (int) $orderData['USER_ID']; } unset($orderData, $orderIterator); if ($userId <= 0) { return false; } self::initUseMode(self::MODE_ORDER, array('userId' => $userId, 'orderId' => $order)); if (!self::isSuccess()) { return false; } self::$coupons = array(); self::saveToStorage(); return true; }
function ExportOrders2Xml($arFilter = array(), $nTopCount = 0, $currency = "", $crmMode = false, $time_limit = 0, $version = false, $arOptions = array()) { self::setVersionSchema($version); self::setCrmMode($crmMode); self::setCurrencySchema($currency); $count = false; if (IntVal($nTopCount) > 0) { $count = array("nTopCount" => $nTopCount); } $end_time = self::getEndTime($time_limit); if (IntVal($time_limit) > 0) { $lastOrderPrefix = self::getOrderPrefix(); if (self::$crmMode) { $lastOrderPrefix = md5(serialize($arFilter)); if (!empty($_SESSION["BX_CML2_EXPORT"][$lastOrderPrefix]) && IntVal($nTopCount) > 0) { $count["nTopCount"] = $count["nTopCount"] + count($_SESSION["BX_CML2_EXPORT"][$lastOrderPrefix]); } } else { if (IntVal($_SESSION["BX_CML2_EXPORT"][$lastOrderPrefix]) > 0) { $arFilter["<ID"] = $_SESSION["BX_CML2_EXPORT"][$lastOrderPrefix]; } } } self::$arResultStat = array("ORDERS" => 0, "CONTACTS" => 0, "COMPANIES" => 0); $bExportFromCrm = self::isExportFromCRM($arOptions); //$paySystems = self::getSalePaySystem(); //$delivery = self::getSaleDelivery(); $arStore = self::getCatalogStore(); $arMeasures = self::getCatalogMeasure(); self::setCatalogMeasure($arMeasures); $arAgent = self::getSaleExport(); if (self::$crmMode) { self::setXmlEncoding("UTF-8"); $arCharSets = self::getSite(); } echo self::getXmlRootName(); ?> <<?php echo CSaleExport::getTagName("SALE_EXPORT_COM_INFORMATION"); ?> <?php echo self::getCmrXmlRootNameParams(); ?> ><?php $arOrder = array("ID" => "DESC"); if (self::$crmMode) { $arOrder = array("DATE_UPDATE" => "ASC"); } $arSelect = array("ID", "LID", "PERSON_TYPE_ID", "PAYED", "DATE_PAYED", "EMP_PAYED_ID", "CANCELED", "DATE_CANCELED", "EMP_CANCELED_ID", "REASON_CANCELED", "STATUS_ID", "DATE_STATUS", "PAY_VOUCHER_NUM", "PAY_VOUCHER_DATE", "EMP_STATUS_ID", "PRICE_DELIVERY", "ALLOW_DELIVERY", "DATE_ALLOW_DELIVERY", "EMP_ALLOW_DELIVERY_ID", "PRICE", "CURRENCY", "DISCOUNT_VALUE", "SUM_PAID", "USER_ID", "PAY_SYSTEM_ID", "DELIVERY_ID", "DATE_INSERT", "DATE_INSERT_FORMAT", "DATE_UPDATE", "USER_DESCRIPTION", "ADDITIONAL_INFO", "COMMENTS", "TAX_VALUE", "STAT_GID", "RECURRING_ID", "ACCOUNT_NUMBER", "SUM_PAID", "DELIVERY_DOC_DATE", "DELIVERY_DOC_NUM", "TRACKING_NUMBER", "STORE_ID", "ID_1C", "VERSION", "USER.XML_ID"); $bCrmModuleIncluded = false; if ($bExportFromCrm) { $arSelect[] = "UF_COMPANY_ID"; $arSelect[] = "UF_CONTACT_ID"; if (IsModuleInstalled("crm") && CModule::IncludeModule("crm")) { $bCrmModuleIncluded = true; } } $filter = array('select' => $arSelect, 'filter' => $arFilter, 'order' => $arOrder, 'limit' => $count["nTopCount"]); if (!empty($arOptions['RUNTIME']) && is_array($arOptions['RUNTIME'])) { $filter['runtime'] = $arOptions['RUNTIME']; } $dbOrderList = \Bitrix\Sale\Internals\OrderTable::getList($filter); //$dbOrderList = CSaleOrder::GetList($arOrder, $arFilter, false, $count, $arSelect); while ($arOrder = $dbOrderList->Fetch()) { $order = \Bitrix\Sale\Order::load($arOrder['ID']); /* @var $order \Bitrix\Sale\Order*/ $arOrder['DATE_STATUS'] = $arOrder['DATE_STATUS']->toString(); $arOrder['DATE_INSERT'] = $arOrder['DATE_INSERT']->toString(); $arOrder['DATE_UPDATE'] = $arOrder['DATE_UPDATE']->toString(); foreach ($arOrder as $field => $value) { if (self::isFormattedDateFields('Order', $field)) { $arOrder[$field] = self::getFormatDate($value); } } if (self::$crmMode) { if (self::getVersionSchema() > self::DEFAULT_VERSION && is_array($_SESSION["BX_CML2_EXPORT"][$lastOrderPrefix]) && in_array($arOrder["ID"], $_SESSION["BX_CML2_EXPORT"][$lastOrderPrefix]) && empty($arFilter["ID"])) { continue; } ob_start(); } self::$arResultStat["ORDERS"]++; $agentParams = array_key_exists($arOrder["PERSON_TYPE_ID"], $arAgent) ? $arAgent[$arOrder["PERSON_TYPE_ID"]] : array(); $arResultPayment = self::getPayment($arOrder); $paySystems = $arResultPayment['paySystems']; $arPayment = $arResultPayment['payment']; $arResultShipment = self::getShipment($arOrder); $arShipment = $arResultShipment['shipment']; $delivery = $arResultShipment['deliveryServices']; self::setDeliveryAddress(''); self::setSiteNameByOrder($arOrder); $saleProperties = self::getSaleProperties($order, $arOrder, $agentParams, $bExportFromCrm, $bCrmModuleIncluded, $paySystems, $delivery, $arOptions); $arProp = $saleProperties['arProp']; $agent = $saleProperties['agent']; $arOrderTax = CSaleExport::getOrderTax($arOrder["ID"]); $xmlResult['OrderTax'] = self::getXMLOrderTax($arOrderTax); self::setOrderSumTaxMoney(self::getOrderSumTaxMoney($arOrderTax)); $xmlResult['Contragents'] = self::getXmlContragents($arOrder, $arProp, $agent, $bExportFromCrm ? array("EXPORT_FROM_CRM" => "Y") : array()); $xmlResult['OrderDiscount'] = self::getXmlOrderDiscount($arOrder); $xmlResult['SaleStore'] = self::getXmlSaleStore($arOrder, $arStore); // self::getXmlSaleStoreBasket($arOrder,$arStore); $basketItems = self::getXmlBasketItems('Order', $arOrder, array('ORDER_ID' => $arOrder['ID']), array(), $arShipment); $xmlResult['BasketItems'] = $basketItems['outputXML']; $xmlResult['SaleProperties'] = self::getXmlSaleProperties($arOrder, $arShipment, $arPayment, $agent, $agentParams, $bExportFromCrm); self::OutputXmlDocument('Order', $xmlResult, $arOrder); if (self::getVersionSchema() >= self::PARTIAL_VERSION) { self::OutputXmlDocumentsByType('Payment', $xmlResult, $arOrder, $arPayment); self::OutputXmlDocumentsByType('Shipment', $xmlResult, $arOrder, $arShipment); self::OutputXmlDocumentRemove('Shipment', $arOrder); } if (self::$crmMode) { $c = ob_get_clean(); $c = CharsetConverter::ConvertCharset($c, $arCharSets[$arOrder["LID"]], "utf-8"); echo $c; $_SESSION["BX_CML2_EXPORT"][$lastOrderPrefix][] = $arOrder["ID"]; } else { $_SESSION["BX_CML2_EXPORT"][$lastOrderPrefix] = $arOrder["ID"]; } if (self::checkTimeIsOver($time_limit, $end_time)) { break; } } ?> </<?php echo CSaleExport::getTagName("SALE_EXPORT_COM_INFORMATION"); ?> ><?php return self::$arResultStat; }
unset($countQuery); $totalCount = (int) $totalCount['CNT']; if ($totalCount > 0) { $totalPages = ceil($totalCount / $navyParams['SIZEN']); if ($navyParams['PAGEN'] > $totalPages) { $navyParams['PAGEN'] = $totalPages; } $getListParams['limit'] = $navyParams['SIZEN']; $getListParams['offset'] = $navyParams['SIZEN'] * ($navyParams['PAGEN'] - 1); } else { $navyParams['PAGEN'] = 1; $getListParams['limit'] = $navyParams['SIZEN']; $getListParams['offset'] = 0; } } $dbOrderList = new CAdminResult(\Bitrix\Sale\Internals\OrderTable::getList($getListParams), $sTableID_tab3); if ($usePageNavigation) { $dbOrderList->NavStart($getListParams['limit'], $navyParams['SHOW_ALL'], $navyParams['PAGEN']); $dbOrderList->NavRecordCount = $totalCount; $dbOrderList->NavPageCount = $totalPages; $dbOrderList->NavPageNomer = $navyParams['PAGEN']; } else { $dbOrderList->NavStart(); } // $dbOrderList->NavStart(); $lAdmin_tab3->NavText($dbOrderList->GetNavPrint(GetMessage('BUYER_ORDER_LIST'))); $orderHeader = array(array("id" => "ID", "content" => "ID", "sort" => "ID", "default" => true), array("id" => "STATUS_ID", "content" => GetMessage("BUYERS_H_STATUS"), "sort" => "STATUS_ID", "default" => true), array("id" => "PAYED", "content" => GetMessage("BUYERS_H_PAID"), "sort" => "PAYED", "default" => true), array("id" => "ALLOW_DELIVERY", "content" => GetMessage("BUYER_LAST_H_ALLOW_DELIVERY"), "sort" => "", "default" => true), array("id" => "PRODUCT", "content" => GetMessage("BUYERS_H_ALL_PRODUCT"), "sort" => "", "default" => true), array("id" => "PRICE", "content" => GetMessage("BUYERS_H_SUM"), "sort" => "PRICE", "default" => true), array("id" => "DATE_INSERT", "content" => GetMessage("BUYERS_H_DATE_INSERT"), "sort" => "DATE_INSERT", "default" => true)); if (count($arSites) > 1) { $orderHeader[] = array("id" => "LID", "content" => GetMessage("BUYERS_H_SITE"), "sort" => "LID", "default" => true); } $lAdmin_tab3->AddHeaders($orderHeader);
BEFORE INSERT ON B_SALE_BASKET_PROPS FOR EACH ROW BEGIN IF :NEW.ID IS NULL THEN SELECT SQ_B_SALE_BASKET_PROPS.NEXTVAL INTO :NEW.ID FROM dual; END IF; END;'); } } } if (empty($error)) { $message = Loc::getMessage('SALE_CONVERTER_AJAX_STEP_FINAL'); $type = 'OK'; if (\Bitrix\Main\ModuleManager::isModuleInstalled('catalog') && \Bitrix\Main\Config\Option::get('sale', 'basket_discount_converted')) { $countQuery = new \Bitrix\Main\Entity\Query(\Bitrix\Sale\Internals\OrderTable::getEntity()); $countQuery->addSelect(new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(1)')); $countQuery->setFilter(array('ORDER_DISCOUNT_DATA.ID' => null)); $totalCount = $countQuery->setLimit(1)->setOffset(null)->exec()->fetch(); unset($countQuery); if ((int) $totalCount['CNT'] > 0) { $adminNotify = false; $adminNotifyIterator = CAdminNotify::GetList(array(), array('MODULE_ID' => 'sale', 'TAG' => 'BASKET_DISCOUNT_CONVERTED')); if (!$adminNotifyIterator) { $adminNotify = $adminNotifyIterator->Fetch(); } unset($adminNotifyIterator); if (empty($adminNotify)) { $langMess = array(); $langList = array(); $languageIterator = \Bitrix\Main\Localization\LanguageTable::getList(array('select' => array('ID'), 'filter' => array('=ACTIVE' => 'Y')));
/** * @internal * @param $id * * @return Sale\Result * @throws Exception * @throws \Bitrix\Main\ArgumentNullException */ protected static function setIdAsAccountNumber($id) { $result = new Sale\Result(); $isOrderConverted = \Bitrix\Main\Config\Option::get("main", "~sale_converted_15", 'N'); if ($isOrderConverted == "Y") { try { /** @var \Bitrix\Sale\Result $r */ $r = \Bitrix\Sale\Internals\OrderTable::update($id, array("ACCOUNT_NUMBER" => $id)); $res = $r->isSuccess(true); } catch (\Bitrix\Main\DB\SqlQueryException $exception) { $res = false; } } else { $res = CSaleOrder::Update($id, array("ACCOUNT_NUMBER" => $id), false); } if (!$res) { $result->addError(new Sale\ResultError(Loc::getMessage('SALE_ORDER_GENERATE_ACCOUNT_NUMBER_ORDER_NUMBER_IS_NOT_SET_AS_ID'), 'SALE_ORDER_GENERATE_ACCOUNT_NUMBER_ORDER_NUMBER_IS_NOT_SET_AS_ID')); return $result; } $result->setData(array('ACCOUNT_NUMBER' => $id)); return $result; }
die; } IncludeModuleLangFile(__FILE__); if (!isset($arFilter) || !is_array($arFilter)) { die("Wrong use 1"); } if (!isset($arSelectFields) || !is_array($arSelectFields)) { die("Wrong use 2"); } $fieldsSeparator = ","; $filter = array('filter' => $arFilter, 'select' => $arSelectFields, 'runtime' => $runtimeFields); if (!empty($by)) { $order = !empty($order) && $order == "DESC" ? "DESC" : "ASC"; $filter['order'] = array($by => $order); } $dbOrderList = \Bitrix\Sale\Internals\OrderTable::getList($filter); ob_start(); for ($i = 0, $max = count($arShownFieldsParams); $i < $max; $i++) { switch ($arShownFieldsParams[$i]["KEY"]) { case "ID": echo "\"" . str_replace("\"", "\"\"", $arShownFieldsParams[$i]["COLUMN_NAME"]) . "\","; echo "\"" . str_replace("\"", "\"\"", GetMessage("SEXC_ORDER_DATE")) . "\""; break; case "PAYED": echo "\"" . str_replace("\"", "\"\"", $arShownFieldsParams[$i]["COLUMN_NAME"]) . "\","; echo "\"" . str_replace("\"", "\"\"", GetMessage("SEXC_PAY_DATE")) . "\""; break; default: echo "\"" . str_replace("\"", "\"\"", $arShownFieldsParams[$i]["COLUMN_NAME"]) . "\""; break; }
$filter_date_to = $_REQUEST["filter_date_to"]; if (StrLen($filter_date_from) <= 0 && StrLen($filter_date_to) <= 0) { $filter_date_from = date($DB->DateFormatToPHP(CSite::GetDateFormat("SHORT")), mktime(0, 0, 0, date("m") - 3, 1, date("Y"))); $filter_date_to = date($DB->DateFormatToPHP(CSite::GetDateFormat("SHORT")), mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"))); } $arResult["FILTER"] = array("filter_date_from" => $filter_date_from, "filter_date_to" => $filter_date_to); $arResult["CURRENT_PAGE_PARAM"] = $APPLICATION->GetCurPageParam("", array("filter_date_from", "filter_date_to")); $arResult["CURRENT_PAGE"] = $APPLICATION->GetCurPage(); $arFilter = array("=AFFILIATE_ID" => $arAffiliate["ID"], "=ALLOW_DELIVERY" => "Y", "=CANCELED" => "N", "=LID" => SITE_ID); if (StrLen($filter_date_from) > 0) { $arFilter[">=DATE_ALLOW_DELIVERY"] = Trim($filter_date_from); } if (StrLen($filter_date_to) > 0) { $arFilter["<=DATE_ALLOW_DELIVERY"] = Trim($filter_date_to); } $dbItemsList = \Bitrix\Sale\Internals\OrderTable::getList(array('filter' => $arFilter, 'select' => array("BASKET_NAME" => 'BASKET.NAME', "BASKET_PRODUCT_ID" => 'BASKET.PRODUCT_ID', "BASKET_MODULE" => 'BASKET.MODULE', "BASKET_PRICE" => 'BASKET.PRICE', "BASKET_CURRENCY" => 'BASKET.CURRENCY', "BASKET_DISCOUNT_PRICE" => 'BASKET.DISCOUNT_PRICE', 'BASKET_QUANTITY' => 'SUM_BASKET_QUANTITY'), 'runtime' => array(new \Bitrix\Main\Entity\ExpressionField('SUM_BASKET_QUANTITY', 'SUM(%s)', array('BASKET.QUANTITY'))), 'order' => array("BASKET.MODULE" => "ASC", "BASKET.NAME" => "ASC", "BASKET.PRODUCT_ID" => "ASC"), 'group' => array("BASKET.MODULE", "BASKET.PRODUCT_ID", "BASKET.NAME", "BASKET.PRICE", "BASKET.CURRENCY", "BASKET.DISCOUNT_PRICE"))); $arResult["ROWS"] = False; if ($arItemsList = $dbItemsList->Fetch()) { $affiliateCurrency = CSaleLang::GetLangCurrency(SITE_ID); $currentBasketModule = $arItemsList["BASKET_MODULE"]; $currentBasketProductID = $arItemsList["BASKET_PRODUCT_ID"]; $currentBasketName = $arItemsList["BASKET_NAME"]; $currentQuantity = 0; $currentSum = 0; $totalQuantity = 0; $totalSum = 0; $arResult["ROWS"] = array(); do { if ($currentBasketModule != $arItemsList["BASKET_MODULE"] || $currentBasketProductID != $arItemsList["BASKET_PRODUCT_ID"] || $currentBasketName != $arItemsList["BASKET_NAME"]) { $arResult["ROWS"][] = array("NAME" => htmlspecialcharsex($currentBasketName), "QUANTITY" => $currentQuantity, "SUM" => $currentSum, "CURRENCY" => $affiliateCurrency, "SUM_FORMAT" => SaleFormatCurrency($currentSum, $affiliateCurrency)); $currentBasketModule = $arItemsList["BASKET_MODULE"];
/** * Perform reading main data from database, no cache is used for it * @throws Main\SystemException * @return void */ protected function obtainDataOrder() { if ($this->options['USE_ACCOUNT_NUMBER']) { $orderDb = \Bitrix\Sale\Internals\OrderTable::getList(array('select' => array('ID'), 'filter' => array("ACCOUNT_NUMBER" => $this->requestData["ID"]))); if ($order = $orderDb->fetch()) { $this->requestData["ID"] = $order["ID"]; } } $sort = array("ID" => "ASC"); $filter = array("ID" => $this->requestData["ID"]); $dbOrder = CSaleOrder::GetList($sort, $filter); $arOrder = $dbOrder->Fetch(); if (empty($arOrder)) { throw new Main\SystemException(str_replace("#ID#", $this->requestData["ID"], Localization\Loc::getMessage("SPOD_NO_ORDER")), self::E_ORDER_NOT_FOUND); } $this->dbResult = $arOrder; }