Ejemplo n.º 1
0
 /**
  * @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']));
     }
 }
Ejemplo n.º 2
0
 /**
  * Сохраняет заказ в БД
  * @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');
     }
 }
Ejemplo n.º 3
0
 /**
  *
  * Инициализирует свойства объекта DDeliveryOrder из stdClass полученный из
  * запроса БД SQLite
  *
  * @param DDeliveryOrder $currentOrder
  * @param \stdClass $item
  */
 public function _initOrderInfo($currentOrder, $item)
 {
     $currentOrder->type = $item->type;
     $currentOrder->paymentVariant = $item->payment_variant;
     $currentOrder->localId = $item->id;
     $currentOrder->city = $item->to_city;
     $currentOrder->localStatus = $item->local_status;
     $currentOrder->ddStatus = $item->dd_status;
     $currentOrder->shopRefnum = $item->shop_refnum;
     $currentOrder->ddeliveryID = $item->ddeliveryorder_id;
     $currentOrder->pointID = $item->point_id;
     $currentOrder->companyId = $item->delivery_company;
     $currentOrder->amount = $currentOrder->getAmount();
     $currentOrder->setPoint(json_decode($item->point, true));
     $currentOrder->addField1 = $item->add_field1;
     $currentOrder->addField2 = $item->add_field2;
     $currentOrder->addField3 = $item->add_field3;
     $orderInfo = json_decode($item->order_info, true);
     $currentOrder->confirmed = $orderInfo['confirmed'];
     $currentOrder->firstName = $orderInfo['firstName'];
     $currentOrder->secondName = $orderInfo['secondName'];
     $currentOrder->toPhone = $orderInfo['to_phone'];
     $currentOrder->declaredPrice = $orderInfo['declaredPrice'];
     $currentOrder->paymentPrice = $orderInfo['paymentPrice'];
     $currentOrder->toStreet = $orderInfo['toStreet'];
     $currentOrder->toHouse = $orderInfo['toHouse'];
     $currentOrder->toFlat = $orderInfo['toFlat'];
     $currentOrder->comment = $orderInfo['comment'];
     $currentOrder->cityName = $orderInfo['city_name'];
     $currentOrder->toHousing = $orderInfo['toHousing'];
     $currentOrder->toEmail = $orderInfo['toEmail'];
     $currentOrder->toIndex = $orderInfo['toIndex'];
 }
Ejemplo n.º 4
0
 /**
  *
  * Есть ли необходимость отправлять заказ на сервер 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;
 }