Exemplo n.º 1
0
    /**
     * @brief Main Form Method
     *
     * @return Rendered form
     */
    public function getContent()
    {
        $idShop = isset($this->context->shop->id) ? $this->context->shop->id : 1;
        $idGroupShop = isset($this->context->shop->id_group_shop) ? $this->context->shop->id_group_shop : 1;
        if (Tools::isSubmit('SubmitShipwireSettings')) {
            if (Validate::isEmail(Tools::getValue('shipwire_api_user'))) {
                Configuration::updateValue('SHIPWIRE_API_CONNECTED', 0);
                Configuration::updateValue('SHIPWIRE_API_USER', Tools::getValue('shipwire_api_user'));
                Configuration::updateValue('SHIPWIRE_API_PASSWD', $this->_cipherTool->encrypt(Tools::getValue('shipwire_api_passwd')));
                $this->dParams['confirmMessage'] = $this->_displayConfirmation();
                Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'shipwire_order` ' . (isset($this->context->shop->id) && isset($this->context->shop->id_group_shop) ? 'WHERE `id_shop` = ' . (int) $this->context->shop->id . '
						AND `id_group_shop` = ' . (int) $this->context->shop->id_group_shop : ''));
                Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'shipwire_stock` ' . (isset($this->context->shop->id) && isset($this->context->shop->id_group_shop) ? 'WHERE `id_shop` = ' . (int) $this->context->shop->id . '
						AND `id_group_shop` = ' . (int) $this->context->shop->id_group_shop : ''));
            } else {
                $this->dParams['confirmMessage'] = $this->_displayConfirmation($this->l('Please enter a valid email address.'), 'error');
            }
        } elseif (Tools::isSubmit('SubmitShipwireTestConnection')) {
            $connectionTestResult = $this->_testConnection();
        } elseif (Tools::isSubmit('SubmitShipwireOptions')) {
            $duplicates = 0;
            Configuration::updateValue('SHIPWIRE_COMMIT_ID', (int) Tools::getValue('shipwire_commit_id'));
            Configuration::updateValue('SHIPWIRE_SENT_ID', (int) Tools::getValue('shipwire_sent_id'));
            Configuration::updateValue('SHIPWIRE_DELIVERED_ID', (int) Tools::getValue('shipwire_delivered_id'));
            Configuration::updateValue('SHIPWIRE_LOG_LIFE', (int) Tools::getValue('shipwire_log_life') < 1 ? 1 : (int) Tools::getValue('shipwire_log_life'));
            // Carrier selection
            //GD
            if (Tools::getValue('shipwire_gd') != Tools::getValue('shipwire_1d') && Tools::getValue('shipwire_gd') != Tools::getValue('shipwire_2d') && Tools::getValue('shipwire_gd') != Tools::getValue('shipwire_intl') || Tools::getValue('shipwire_gd') == 0) {
                Configuration::updateValue('SHIPWIRE_GD', (int) Tools::getValue('shipwire_gd'));
            } else {
                $duplicates = 1;
            }
            //1d
            if (Tools::getValue('shipwire_1d') != Tools::getValue('shipwire_gd') && Tools::getValue('shipwire_1d') != Tools::getValue('shipwire_2d') && Tools::getValue('shipwire_1d') != Tools::getValue('shipwire_intl') || Tools::getValue('shipwire_1d') == 0) {
                Configuration::updateValue('SHIPWIRE_1D', (int) Tools::getValue('shipwire_1d'));
            } else {
                $duplicates = 1;
            }
            //2d
            if (Tools::getValue('shipwire_2d') != Tools::getValue('shipwire_gd') && Tools::getValue('shipwire_2d') != Tools::getValue('shipwire_1d') && Tools::getValue('shipwire_2d') != Tools::getValue('shipwire_intl') || Tools::getValue('shipwire_2d') == 0) {
                Configuration::updateValue('SHIPWIRE_2D', (int) Tools::getValue('shipwire_2d'));
            } else {
                $duplicates = 1;
            }
            //INTL
            if (Tools::getValue('shipwire_intl') != Tools::getValue('shipwire_gd') && Tools::getValue('shipwire_intl') != Tools::getValue('shipwire_1d') && Tools::getValue('shipwire_intl') != Tools::getValue('shipwire_2d') || Tools::getValue('shipwire_intl') == 0) {
                Configuration::updateValue('SHIPWIRE_INTL', (int) Tools::getValue('shipwire_intl'));
            } else {
                $duplicates = 1;
            }
            //Check for errors
            if ($duplicates) {
                $this->dParams['confirmMessage'] = $this->_displayConfirmation($this->l('The shipping methods were not saved
				because duplicate values are not allowed.'), 'warn');
            } else {
                $this->dParams['confirmMessage'] = $this->_displayConfirmation();
            }
        } elseif (Tools::isSubmit('SubmitUpdateStock')) {
            if ($this->_shipWireInventoryUpdate->getInventory()) {
                $this->dParams['confirmMessage'] = $this->_displayConfirmation($this->l('Stock updated.'));
            } else {
                $this->dParams['confirmMessage'] = $this->_displayConfirmation($this->l('Stock update failed'), 'error');
            }
        } elseif (Tools::isSubmit('SubmitUpdateTracking')) {
            if (ShipwireTracking::updateTracking(true, $idShop, $idGroupShop)) {
                $this->dParams['confirmMessage'] = $this->_displayConfirmation($this->l('Transactions updated.'));
            } else {
                $this->dParams['confirmMessage'] = $this->_displayConfirmation($this->l('Transactions update failed.'), 'error');
            }
        } elseif (Tools::isSubmit('resend_id_order')) {
            if ($this->updateOrderStatus(Tools::getValue('resend_id_order'))) {
                $this->dParams['confirmMessage'] = $this->_displayConfirmation($this->l('Order successfully resent.'));
            } else {
                $this->dParams['confirmMessage'] = $this->_displayConfirmation($this->l('Error while sending. Try again later.'), 'error');
            }
        } elseif (Tools::isSubmit('SubmitResendFailedTransactions')) {
            $d = Db::getInstance()->ExecuteS('SELECT `id_order`
				FROM `' . _DB_PREFIX_ . 'shipwire_order`
				WHERE `transaction_ref` IS NULL OR `transaction_ref` = \'\'' . (isset($this->context->shop->id) ? 'AND `id_shop` = \'' . (int) $this->context->shop->id . '\'' : ''));
            foreach ($d as $line) {
                $this->updateOrderStatus($line['id_order']);
            }
            if (ShipwireTracking::updateTracking(true, (int) $idShop, (int) $idGroupShop)) {
                $this->dParams['confirmMessage'] = $this->_displayConfirmation($this->l('Transactions successfully resent.'));
            } else {
                $this->dParams['confirmMessage'] = $this->_displayConfirmation($this->l('Error resending transactions.'), 'error');
            }
        } elseif (Tools::isSubmit('SubmitCleanLogs')) {
            if (Db::getInstance()->Execute('TRUNCATE `' . _DB_PREFIX_ . 'shipwire_log`')) {
                $this->dParams['confirmMessage'] = $this->_displayConfirmation($this->l('Logs empty.'));
            } else {
                $this->dParams['confirmMessage'] = $this->_displayConfirmation($this->l('Error deleting logs.'), 'error');
            }
        }
        $confValues = Configuration::getMultiple(array('SHIPWIRE_API_USER', 'SHIPWIRE_API_PASSWD'));
        /// @todo : check if these assigns are necessary
        $this->dParams['defaultOriginServerURL'] = 'http://' . Tools::safeOutput(Configuration::get('PS_SHOP_DOMAIN')) . __PS_BASE_URI__;
        $this->dParams['serverRequestUri'] = Tools::safeOutput($_SERVER['REQUEST_URI']);
        $this->dParams['displayName'] = Tools::safeOutput($this->displayName);
        if (isset($connectionTestResult)) {
            $this->dParams['connectionTestResult'] = $connectionTestResult;
        }
        if (isset($confValues['SHIPWIRE_API_USER'])) {
            $this->dParams['apiEmail'] = Tools::safeOutput($confValues['SHIPWIRE_API_USER']);
        }
        if (isset($confValues['SHIPWIRE_API_PASSWD'])) {
            $this->dParams['apiPasswd'] = Tools::safeOutput($this->_cipherTool->decrypt($confValues['SHIPWIRE_API_PASSWD']));
        }
        return $this->_displayContent();
    }
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <*****@*****.**>
*  @copyright  2007-2012 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/
include_once dirname(__FILE__) . '/../../config/config.inc.php';
if (isset($_GET['secure_key']) || isset($_ARGV[1])) {
    $secureKey = md5(_COOKIE_KEY_ . Configuration::get('PS_SHOP_NAME'));
    if (!empty($secureKey) && ($secureKey == $_GET['secure_key'] || isset($_ARGV[1]) && $secureKey == $_ARGV[1])) {
        // Clean logs
        $logDeleteDate = date('Y-m-d', mktime(0, 0, 0, date('n'), date('j') - Configuration::get('SHIPWIRE_LOG_LIFE'), date('Y'))) . ' 00:00:00';
        Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'shipwire_log` WHERE `date_added` < \'' . pSQL($logDeleteDate) . '\'');
        if (!class_exists('Shipwire')) {
            require_once dirname(__FILE__) . '/shipwire.php';
        }
        require_once dirname(__FILE__) . '/lib/ShipwireApi.php';
        require_once dirname(__FILE__) . '/lib/ShipwireTracking.php';
        $m = new Shipwire();
        $d = Db::getInstance()->ExecuteS('SELECT `id_order` FROM `' . _DB_PREFIX_ . 'shipwire_order` WHERE `transaction_ref` IS NULL OR `transaction_ref` = \'\'');
        foreach ($d as $line) {
            $m->updateOrderStatus($line['id_order']);
        }
        ShipwireTracking::updateTracking();
        // This will be called directly thru the browser or cronjob
    }
    die('Invalid key.');
}