Exemplo n.º 1
0
 /**
  * get merchant api
  *
  * @param $storeId
  */
 protected function _initMerchantApi($storeId)
 {
     /* @var $config Shopgate_Framework_Model_Config */
     if ($this->_config == null) {
         $this->_config = Mage::helper("shopgate/config")->getConfig($storeId);
     }
     $builder = new ShopgateBuilder($this->_config);
     $this->_merchantApi = $builder->buildMerchantApi();
 }
Exemplo n.º 2
0
 public function hookAdminOrder($params)
 {
     include_once dirname(__FILE__) . '/backward_compatibility/backward.php';
     $id_order = $params['id_order'];
     $shopgateOrder = PSShopgateOrder::instanceByOrderId($id_order);
     if (Tools::isSubmit('updateShopgateOrder')) {
         $shopgate_order = Tools::getValue('shopgateOrder');
         $shippingService = $shopgate_order['shipping_service'];
         $trackingNumber = $shopgate_order['tracking_number'];
         if (isset($shippingService)) {
             try {
                 $shopgateConfig = new ShopgateConfigPresta();
                 $shopgateBuilder = new ShopgateBuilder($shopgateConfig);
                 $shopgateMerchantApi = $shopgateBuilder->buildMerchantApi();
                 $shopgateMerchantApi->addOrderDeliveryNote($shopgateOrder->order_number, $shippingService, $trackingNumber, true, false);
             } catch (ShopgateMerchantApiException $e) {
                 $error = $e->getMessage();
             }
             $shopgateOrder->shipping_service = $shippingService;
             $shopgateOrder->tracking_number = $trackingNumber;
             $shopgateOrder->update();
         }
     }
     if (!Validate::isLoadedObject($shopgateOrder)) {
         return '';
     }
     $sOrder = null;
     $error = null;
     try {
         $shopgateConfig = new ShopgateConfigPresta();
         $shopgateBuilder = new ShopgateBuilder($shopgateConfig);
         $shopgateMerchantApi = $shopgateBuilder->buildMerchantApi();
         $orders = $shopgateMerchantApi->getOrders(array('order_numbers[0]' => $shopgateOrder->order_number));
         foreach ($orders->getData() as $o) {
             /* @var $o ShopgateOrder */
             if ($o->getOrderNumber() == $shopgateOrder->order_number) {
                 $sOrder = $o;
             }
         }
     } catch (ShopgateMerchantApiException $e) {
         $error = $e->getMessage();
     }
     $paymentInfoStrings = array('shopgate_payment_name' => $this->l('Payment name'), 'upp_transaction_id' => $this->l('Transaction ID'), 'authorization' => $this->l('Authorization'), 'settlement' => $this->l('Settlement'), 'purpose' => $this->l('Purpose'), 'billsafe_transaction_id' => $this->l('Transaction ID'), 'reservation_number' => $this->l('Reservation number'), 'activation_invoice_number' => $this->l('Invoice activation number'), 'bank_account_holder' => $this->l('Account holder'), 'bank_account_number' => $this->l('Account number'), 'bank_code' => $this->l('Bank code'), 'bank_name' => $this->l('Bank name'), 'iban' => $this->l('IBAN'), 'bic' => $this->l('BIC'), 'transaction_id' => $this->l('Transaction ID'), 'payer_id' => $this->l('Payer ID'), 'payer_email' => $this->l('Payer email'));
     $sOrderDeliveryNotes = array();
     foreach ($sOrder->getDeliveryNotes() as $notes) {
         $sOrderDeliveryNotes[] = array('shipping_service_id' => $notes->getShippingServiceId(), 'tracking_number' => $notes->getTrackingNumber(), 'shipping_time' => $notes->getShippingTime());
     }
     // build comments
     $comments = array();
     foreach ($sOrder->jsonDecode($shopgateOrder->comments) as $text => $information) {
         $comments[] = sprintf($this->l($text), $information);
     }
     $this->context->smarty->assign('sOrder', $sOrder);
     $this->context->smarty->assign('sOrderComments', $comments);
     $this->context->smarty->assign('sOrderPaymentInfos', $sOrder->getPaymentInfos());
     $this->context->smarty->assign('sOrderDeliveryNotes', $sOrderDeliveryNotes);
     $this->context->smarty->assign('sShopNumber', $shopgateOrder->shop_number);
     $this->context->smarty->assign('shopgate_error', $error);
     $this->context->smarty->assign('paymentInfoStrings', $paymentInfoStrings);
     $this->context->smarty->assign('shopgateOrder', $shopgateOrder);
     $this->context->smarty->assign('shippingInfos', $sOrder->getShippingInfos());
     $this->context->smarty->assign('shipping_service_list', $this->shipping_service_list);
     $this->context->smarty->assign('sModDir', $this->_path);
     $this->context->smarty->assign('api_url', Tools::getHttpHost(true, true) . $this->_path . 'api.php');
     return $this->display(__FILE__, 'views/templates/admin/admin_order.tpl');
 }
Exemplo n.º 3
0
 /**
  * @param string    $message
  * @param int       $errorcount
  */
 public function setShippingComplete(&$message, &$errorcount)
 {
     $log = ShopgateLogger::getInstance();
     $shopgateConfig = new ShopgateConfigPrestashop();
     $shopgateBuilder = new ShopgateBuilder($shopgateConfig);
     $shopgateMerchantApi = $shopgateBuilder->buildMerchantApi();
     try {
         /** @var OrderCore $orderCore */
         $orderCore = new Order($this->id_order);
         $trackingCode = $orderCore->shipping_number;
         if (Tools::strlen($trackingCode) > 32) {
             $log->log("TrackingCode '" . $trackingCode . "' is too long", ShopgateLogger::LOGTYPE_DEBUG);
             $trackingCode = '';
         }
         $shopgateMerchantApi->addOrderDeliveryNote($this->order_number, ShopgateDeliveryNote::OTHER, $trackingCode, true);
         $message .= "Setting \"shipping complete\" for shopgate-order #{$this->order_number} successfully completed\n";
         $this->is_sent_to_shopgate = 1;
         $this->tracking_number = $trackingCode;
         $this->update();
     } catch (ShopgateMerchantApiException $e) {
         if ($e->getCode() == ShopgateMerchantApiException::ORDER_SHIPPING_STATUS_ALREADY_COMPLETED) {
             $log->log("Order with order-number #{$this->order_number} already marked as complete at shopgate.", ShopgateLogger::LOGTYPE_DEBUG);
             $e = null;
             $this->is_sent_to_shopgate = 1;
             $this->update();
         }
     } catch (Exception $e) {
         $errorcount++;
         $message .= "Error while setting \"shipping complete\" for shopgate-order #{$this->order_number}\n";
     }
 }
Exemplo n.º 4
0
 /**
  * This method gets called when the order status is changed in the admin area of the Prestashop backend
  *
  * @param $params
  */
 public function hookUpdateOrderStatus($params)
 {
     $id_order = $params['id_order'];
     $newOrderState = $params['newOrderStatus'];
     $shopgateOrder = ShopgateOrderPrestashop::loadByOrderId($id_order);
     $shopgateConfig = new ShopgateConfigPrestashop();
     $cancellationStatus = Configuration::get('SG_CANCELLATION_STATUS');
     $shopgateBuilder = new ShopgateBuilder($shopgateConfig);
     $shopgateMerchantApi = $shopgateBuilder->buildMerchantApi();
     if (!is_object($shopgateOrder) || !$shopgateOrder->id_shopgate_order) {
         return;
     }
     try {
         $shippedOrderStates = array();
         if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
             $orderStates = OrderState::getOrderStates($this->context->language->id);
             foreach ($orderStates as $orderState) {
                 if ($orderState['shipped']) {
                     $shippedOrderStates[$orderState['id_order_state']] = 1;
                 }
             }
         } else {
             // Default methods for Prestashop version < 1.5.0.0
             $shippedOrderStates[_PS_OS_DELIVERED_] = 1;
             $shippedOrderStates[_PS_OS_SHIPPING_] = 1;
         }
         if (!empty($shippedOrderStates[$newOrderState->id])) {
             $shopgateMerchantApi->setOrderShippingCompleted($shopgateOrder->order_number);
         }
         $message = '';
         if ($cancellationStatus == $newOrderState->id) {
             $shopgateOrder->cancelOrder($message);
         }
     } catch (ShopgateMerchantApiException $e) {
         $msg = new Message();
         $msg->message = $this->l('On order state') . ': ' . $orderState->name . ' - ' . $this->l('Shopgate status was not updated because of following error') . ': ' . $e->getMessage();
         $msg->id_order = $id_order;
         $msg->id_employee = isset($params['cookie']->id_employee) ? $params['cookie']->id_employee : 0;
         $msg->private = true;
         $msg->add();
     }
 }