Пример #1
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";
     }
 }
Пример #2
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();
 }
Пример #3
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');
 }
Пример #4
0
 /**
  * @param ShopgateBuilder $builder If empty, the default ShopgateBuilder will be instantiated.
  */
 public final function __construct(ShopgateBuilder $builder = null)
 {
     // some default values
     $this->splittedExport = false;
     $this->exportOffset = 0;
     $this->exportLimit = 1000;
     // fire the plugin's startup callback
     try {
         $this->startup();
     } catch (ShopgateLibraryException $e) {
         // logging is done in exception constructor
     }
     // build the object graph and get needed objects injected via set* methods
     if (empty($builder)) {
         $builder = new ShopgateBuilder($this->config);
     }
     $builder->buildLibraryFor($this);
     // store the builder
     $this->builder = $builder;
 }
Пример #5
0
 /**
  * Get cached header js for redirect or load and save to cache
  *
  * @param $type  string
  * @param $objId string|int
  * @param $automaticRedirect
  * @return mixed|string|void
  */
 protected function _getCachedJsHeaderByType($type, $objId, $automaticRedirect)
 {
     $storeViewId = $this->_config->getStoreViewId();
     switch ($type) {
         case self::CATEGORY:
             $cacheKey = $storeViewId . '_sg_mobile_category_' . $objId . '_redirect_type_' . intval($automaticRedirect);
             break;
         case self::PRODUCT:
             $cacheKey = $storeViewId . '_sg_mobile_item_' . $objId . '_redirect_type_' . intval($automaticRedirect);
             break;
         case self::PAGE:
             $cacheKey = $storeViewId . '_sg_mobile_page_' . $objId . '_redirect_type_' . intval($automaticRedirect);
             break;
         case self::SEARCH:
             $cacheKey = $storeViewId . '_sg_mobile_catalogsearch_' . md5($objId) . '_redirect_type_' . intval($automaticRedirect);
             break;
         case self::INDEX:
             $cacheKey = $storeViewId . '_sg_mobile_index_redirect_type_' . intval($automaticRedirect);
             break;
         default:
             $cacheKey = $storeViewId . '_sg_mobile_default_type_' . intval($automaticRedirect);
             break;
     }
     $cache = Mage::app()->getCacheInstance();
     $value = $cache->load($cacheKey);
     if ($value !== false) {
         $jsHeader = unserialize($value);
     } else {
         $builder = new ShopgateBuilder($this->_config);
         $shopgateRedirect = $builder->buildRedirect();
         if (!in_array(Mage::app()->getRequest()->getControllerName(), array(self::CATEGORY, self::PRODUCT, self::SEARCH, self::INDEX)) && !Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_ENABLE_DEFAULT_REDIRECT)) {
             $shopgateRedirect->suppressRedirect();
         }
         $disabledRoutes = explode(',', Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_DISABLE_REDIRECT_ROUTES));
         $route = Mage::app()->getRequest()->getRouteName();
         if (in_array($route, $disabledRoutes)) {
             $shopgateRedirect->suppressRedirect();
         }
         $disabledControllers = explode(',', Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_DISABLE_REDIRECT_CONTROLLERS));
         $controllerName = Mage::app()->getRequest()->getControllerName();
         if (in_array($controllerName, $disabledControllers)) {
             $shopgateRedirect->suppressRedirect();
         }
         if ($controllerName == 'product') {
             $productId = Mage::app()->getRequest()->getParam('id');
             $disabledProducts = explode(',', Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_DISABLE_REDIRECT_PRODUCTS));
             if (in_array($productId, $disabledProducts)) {
                 $shopgateRedirect->suppressRedirect();
             }
         }
         if ($controllerName == 'category') {
             $categoryId = Mage::app()->getRequest()->getParam('id');
             $disabledCategories = explode(',', Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_DISABLE_REDIRECT_CATEGORIES));
             if (in_array($categoryId, $disabledCategories)) {
                 $shopgateRedirect->suppressRedirect();
             }
         }
         switch ($type) {
             case self::CATEGORY:
                 $jsHeader = $shopgateRedirect->buildScriptCategory($objId, $automaticRedirect);
                 break;
             case self::PRODUCT:
                 $jsHeader = $shopgateRedirect->buildScriptItem($objId, $automaticRedirect);
                 break;
             case self::PAGE:
                 $jsHeader = $shopgateRedirect->buildScriptCms($objId, $automaticRedirect);
                 break;
             case self::SEARCH:
                 $jsHeader = $shopgateRedirect->buildScriptSearch($objId, $automaticRedirect);
                 break;
             case self::INDEX:
                 $jsHeader = $shopgateRedirect->buildScriptShop($automaticRedirect);
                 break;
             default:
                 $jsHeader = $shopgateRedirect->buildScriptDefault($automaticRedirect);
                 break;
         }
         $cache->save(serialize($jsHeader), $cacheKey, array('shopgate_mobile_redirect', Mage_Core_Model_Layout_Update::LAYOUT_GENERAL_CACHE_TAG), 7200);
     }
     return $jsHeader;
 }
Пример #6
0
 /**
  * @return mixed|string
  */
 public static function calculateRedirect()
 {
     $shopgateConfig = new ShopgateConfigPrestashop();
     $shopgateBuilder = new ShopgateBuilder($shopgateConfig);
     $shopgateRedirect = $shopgateBuilder->buildRedirect();
     $controller = Tools::getValue('controller');
     /**
      * prepare controller for older versions
      */
     if (!$controller) {
         $fileInfo = pathinfo($_SERVER['SCRIPT_NAME']);
         $controller = $fileInfo['filename'];
     }
     switch ($controller) {
         case 'category':
             return $shopgateRedirect->buildScriptCategory(Tools::getValue('id_category', 0));
         case 'product':
             return $shopgateRedirect->buildScriptItem(Tools::getValue('id_product', 0));
         case 'search':
             return $shopgateRedirect->buildScriptSearch(Tools::getValue('search_query', ''));
         case 'index':
             return $shopgateRedirect->buildScriptShop();
         default:
             if ($manufacturerId = Tools::getValue('id_manufacturer')) {
                 /** @var ManufacturerCore $manufacturer */
                 $manufacturer = new Manufacturer($manufacturerId);
                 return $shopgateRedirect->buildScriptBrand($manufacturer->name);
             }
             return $shopgateRedirect->buildScriptDefault();
     }
 }
Пример #7
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();
     }
 }