/** * @param \DDelivery\Order\DDeliveryOrder $order * @throws \Bitrix\Main\ArgumentException */ public function onFinishChange($order) { global $APPLICATION; $point = $order->getPoint(); if ($order->type == DDeliverySDK::TYPE_SELF) { $replaceData = array('%1' => $order->cityName, '%2' => $point['address'], '%3' => $point['delivery_company_name'], '%4' => $point['_id'], '%5' => $point['type'] == 1 ? 'Постомат' : 'ПВЗ'); $replaceData = $APPLICATION->ConvertCharsetArray($replaceData, 'UTF-8', SITE_CHARSET); $comment = GetMessage('DDELIVERY_ABOUT_SELF', $replaceData); } else { if ($order->type == DDeliverySDK::TYPE_COURIER) { $replaceData = array('%1' => $order->getFullAddress(), '%2' => $point['delivery_company_name']); $replaceData = $APPLICATION->ConvertCharsetArray($replaceData, 'UTF-8', SITE_CHARSET); $comment = GetMessage('DDELIVERY_ABOUT_COURIER', $replaceData); } else { $comment = 'error'; } } $orderId = $this->formData['bx_order_id']; $params = array('DD_ABOUT' => $comment, 'DD_LOCAL_ID' => $order->localId); $orderDeliveryTableData = OrderDeliveryTable::getList(array('filter' => array('ORDER_ID' => $orderId)))->fetch(); if ($orderDeliveryTableData) { OrderDeliveryTable::update($orderDeliveryTableData['ID'], array('PARAMS' => serialize($params))); } else { OrderDeliveryTable::add(array('ORDER_ID' => $orderId, 'PARAMS' => serialize($params))); } $order = CSaleOrder::GetByID($orderId); $arDeliveryResult = CSaleDeliveryHandler::CalculateFull('ddelivery', 'ddelivery:all', $order, CSaleLang::GetLangCurrency(SITE_ID), SITE_ID); if ($arDeliveryResult['RESULT'] == 'OK') { CSaleOrder::Update($orderId, array('PRICE_DELIVERY' => $arDeliveryResult['VALUE'])); } }
private function renderChange() { $comment = ''; $point = $this->order->getPoint(); $comment = $this->getPointComment($this->order); $this->order->localId = $this->saveFullOrder($this->order); $this->shop->onFinishChange($this->order); $returnArray = array('html' => '', 'js' => 'change', 'comment' => htmlspecialchars($comment), 'orderId' => $this->order->localId, 'clientPrice' => $this->getClientPrice($point, $this->order, $this->order->type), 'userInfo' => $this->getDDUserInfo($this->order), 'payment' => $this->getAvailablePaymentVariants($this->order)); $returnArray = $this->shop->onFinishResultReturn($this->order, $returnArray); $this->cache->cleanExpired(); return json_encode($returnArray); }
/** * Сохраняет заказ в БД * @param DDeliveryOrder $order * @return string * @throws \DDelivery\DDeliveryException */ public function saveFullOrder($order) { $wasUpdate = 0; $localId = $order->localId; $payment_variant = $order->paymentVariant; $shop_refnum = $order->shopRefnum; $localStatus = $order->localStatus; $ddStatus = $order->ddStatus; $type = $order->type; $to_city = $order->city; $pointID = $order->pointID; $ddeliveryID = $order->ddeliveryID; $delivery_company = $order->companyId; //echo 'pz'; $order_info = json_encode(array('confirmed' => $order->confirmed, 'firstName' => $order->firstName, 'secondName' => $order->secondName, 'to_phone' => $order->getToPhone(), 'declaredPrice' => $order->declaredPrice, 'paymentPrice' => $order->paymentPrice, 'toStreet' => $order->toStreet, 'toHouse' => $order->toHouse, 'toFlat' => $order->toFlat, 'comment' => $order->comment, 'city_name' => $order->cityName, 'toHousing' => $order->toHousing, 'toEmail' => $order->toEmail, 'toIndex' => $order->toIndex)); $point = json_encode($order->getPoint()); $add_field1 = $order->addField1; $add_field2 = $order->addField2; $add_field3 = $order->addField3; $cart = $order->getSerializedProducts(); if ($this->isRecordExist($localId)) { $query = "UPDATE {$this->prefix}orders\n SET payment_variant = :payment_variant,\n shop_refnum = :shop_refnum, local_status = :local_status,\n dd_status = :dd_status, type = :type, to_city =:to_city,\n point_id = :point_id, date = :date,\n ddeliveryorder_id = :ddeliveryorder_id, delivery_company = :delivery_company,\n order_info = :order_info,\n point = :point, add_field1 = :add_field1,\n add_field2 = :add_field2, add_field3 = :add_field3, cart = :cart\n\t\t\t WHERE id=:id"; $stmt = $this->pdo->prepare($query); $stmt->bindParam(':id', $localId); $wasUpdate = 1; } else { $query = "INSERT INTO {$this->prefix}orders(\n payment_variant, shop_refnum, local_status, dd_status, type,\n to_city, point_id, date, ddeliveryorder_id, delivery_company, order_info,\n point, add_field1, add_field2, add_field3, cart\n ) VALUES(\n\t :payment_variant, :shop_refnum, :local_status, :dd_status, :type,\n :to_city, :point_id, :date, :ddeliveryorder_id, :delivery_company, :order_info,\n :point, :add_field1, :add_field2, :add_field3, :cart\n )"; $stmt = $this->pdo->prepare($query); } $stmt->bindParam(':payment_variant', $payment_variant); $stmt->bindParam(':shop_refnum', $shop_refnum); $stmt->bindParam(':local_status', $localStatus); $stmt->bindParam(':dd_status', $ddStatus); $stmt->bindParam(':type', $type); $stmt->bindParam(':to_city', $to_city); $stmt->bindParam(':point_id', $pointID); $dateTime = date("Y-m-d H:i:s"); $stmt->bindParam(':date', $dateTime); $stmt->bindParam(':ddeliveryorder_id', $ddeliveryID); $stmt->bindParam(':delivery_company', $delivery_company); $stmt->bindParam(':order_info', $order_info); $stmt->bindParam(':point', $point); $stmt->bindParam(':add_field1', $add_field1); $stmt->bindParam(':add_field2', $add_field2); $stmt->bindParam(':add_field3', $add_field3); $stmt->bindParam(':cart', $cart); if ($stmt->execute()) { if ($wasUpdate) { return $localId; } else { return $this->pdo->lastInsertId(); } } else { throw new DDeliveryException('Order not saved'); } }
/** * * Есть ли необходимость отправлять заказ на сервер ddelivery * * @param \DDelivery\Order\DDeliveryOrder $order * * @return bool * */ public function sendOrderToDDeliveryServer($order) { $point = $order->getPoint(); if (array_key_exists($point['delivery_company'], $this->getCustomCourierCompanies()) || array_key_exists($point['delivery_company'], $this->getCustomSelfCompanies())) { return false; } return true; }