Exemplo n.º 1
0
 public function postProcess()
 {
     // Check if cart is valid
     $cart = new Cart((int) Tools::getValue('id_cart'));
     if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) {
         $this->returnError('Invalid cart');
     }
     // Check if customer exists
     $customer = new Customer($cart->id_customer);
     if (!Validate::isLoadedObject($customer)) {
         $this->returnError('Invalid customer');
     }
     $currency = new Currency((int) $cart->id_currency);
     $total_paid = Tools::getValue('total_paid');
     $extra_vars = array('transaction_id' => Tools::getValue('transaction_id'));
     // Build the validation token
     $validation_token = md5(Configuration::get('MYMOD_API_CRED_SALT') . Tools::getValue('id_cart') . $total_paid . Tools::getValue('transaction_id'));
     // Check validation token
     if (Tools::getValue('validation_token') != $validation_token) {
         $this->returnError('Invalid token');
     }
     // Validate order
     $this->module->validateOrder($cart->id, Configuration::get('PS_OS_PAYMENT'), $total_paid, $this->module->displayName . ' API', NULL, $extra_vars, (int) $currency->id, false, $customer->secure_key);
     // Redirect on order confirmation page
     $shop = new Shop(Configuration::get('PS_SHOP_DEFAULT'));
     $return_url = Tools::getShopProtocol() . $shop->domain . $shop->getBaseURI();
     $this->returnSuccess($return_url . 'index.php?controller=order-confirmation&id_cart=' . $cart->id . '&id_module=' . $this->module->id . '&id_order=' . $this->module->currentOrder . '&key=' . $customer->secure_key);
 }
Exemplo n.º 2
0
 /**
  * Create a link to a photo
  *
  * @param mixed $photo Photos object (can be an ID supplier, but deprecated)
  * @param string $alias
  * @param int $id_lang
  * @return string
  */
 public static function getPhotosLink($photo, $alias = null, $id_lang = null, $id_shop = null)
 {
     if (!$id_lang) {
         $id_lang = Context::getContext()->language->id;
     }
     if ($id_shop === null) {
         $shop = Context::getContext()->shop;
     } else {
         $shop = new Shop($id_shop);
     }
     $url = 'http://' . $shop->domain . $shop->getBaseURI() . $this->getLangLink($id_lang, null, $id_shop);
     $dispatcher = Dispatcher::getInstance();
     if (!is_object($photo)) {
         if ($alias !== null && !$dispatcher->hasKeyword('photo_rule', $id_lang, 'meta_keywords', $id_shop) && !$dispatcher->hasKeyword('photo_rule', $id_lang, 'meta_title', $id_shop)) {
             return $url . $dispatcher->createUrl('photo_rule', $id_lang, array('id' => (int) $photo, 'rewrite' => (string) $alias), $this->allow, '', $id_shop);
         }
         $photo = new Photos($photo, $id_lang);
     }
     // Set available keywords
     $params = array();
     $params['id'] = $photo->id;
     $params['rewrite'] = !$alias ? $photo->link_rewrite : $alias;
     $params['meta_keywords'] = Tools::str2url($photo->meta_keywords);
     $params['meta_title'] = Tools::str2url($photo->meta_title);
     return $url . $dispatcher->createUrl('photo_rule', $id_lang, $params, $this->allow, '', $id_shop);
 }
Exemplo n.º 3
0
 public function run($params)
 {
     $api_url = Configuration::get('MYMOD_API_URL');
     $api_credentials_id = Configuration::get('MYMOD_API_CRED_ID');
     $api_credentials_salt = Configuration::get('MYMOD_API_CRED_SALT');
     $total_to_pay = (double) $this->context->cart->getOrderTotal(true, Cart::BOTH);
     $id_cart = $this->context->cart->id;
     $payment_token = md5($api_credentials_salt . $id_cart . $total_to_pay);
     $validation_url = $this->context->link->getModuleLink('mymodpayment', 'validationapi');
     $shop = new Shop(Configuration::get('PS_SHOP_DEFAULT'));
     $return_url = Tools::getShopProtocol() . $shop->domain . $shop->getBaseURI();
     $cancel_url = Tools::getShopProtocol() . $shop->domain . $shop->getBaseURI();
     $this->context->smarty->assign('api_url', $api_url);
     $this->context->smarty->assign('api_credentials_id', $api_credentials_id);
     $this->context->smarty->assign('total_to_pay', $total_to_pay);
     $this->context->smarty->assign('id_cart', $id_cart);
     $this->context->smarty->assign('payment_token', $payment_token);
     $this->context->smarty->assign('validation_url', $validation_url);
     $this->context->smarty->assign('return_url', $return_url);
     $this->context->smarty->assign('cancel_url', $cancel_url);
     $this->context->controller->addCSS($this->_path . 'views/css/mymodpayment.css', 'all');
     return $this->module->display($this->file, 'displayPayment.tpl');
 }
 /**
  * Create a link to a category
  *
  * @param mixed $category Category object (can be an ID category, but deprecated)
  * @param string $alias
  * @param int $id_lang
  * @param string $selected_filters Url parameter to autocheck filters of the module blocklayered
  * @return string
  */
 public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null, $id_shop = null)
 {
     if (!$id_lang) {
         $id_lang = Context::getContext()->language->id;
     }
     if ($id_shop === null) {
         $shop = Context::getContext()->shop;
     } else {
         $shop = new Shop($id_shop);
     }
     $url = 'http://' . $shop->domain . $shop->getBaseURI() . $this->getLangLink($id_lang, null, $id_shop);
     if (!is_object($category)) {
         $category = new Category($category, $id_lang);
     }
     // Set available keywords
     $params = array();
     $params['id'] = $category->id;
     $params['rewrite'] = !$alias ? $category->link_rewrite : $alias;
     $params['meta_keywords'] = Tools::str2url($category->meta_keywords);
     $params['meta_title'] = Tools::str2url($category->meta_title);
     // Selected filters is used by the module blocklayered
     $selected_filters = is_null($selected_filters) ? '' : $selected_filters;
     if (empty($selected_filters)) {
         $rule = 'category_rule';
     } else {
         $rule = 'layered_rule';
         $params['selected_filters'] = $selected_filters;
     }
     //$params['category'] = $category->link_rewrite;
     $cats = array();
     $subCategories = $this->_getParentsCategories($category->id);
     $subCategories = is_array($subCategories) === TRUE ? array_reverse($subCategories) : $subCategories;
     $skip_list = Link::$category_disable_rewrite;
     $skip_list[] = $category->id;
     foreach ($subCategories as $cat) {
         if (!in_array($cat['id_category'], $skip_list)) {
             //remove root and home category from the URL
             $cats[] = $cat['link_rewrite'];
         }
     }
     $params['categories'] = implode('/', $cats);
     return $url . Dispatcher::getInstance()->createUrl($rule, $id_lang, $params, $this->allow);
 }
Exemplo n.º 5
0
 /**
  * Create a simple link
  *
  * @param string $controller
  * @param bool $ssl
  * @param int $id_lang
  * @param string|array $request
  * @param bool $request_url_encode Use URL encode
  *
  * @return string Page link
  */
 public function getPageLink($controller, $ssl = false, $id_lang = null, $request = null, $request_url_encode = false, $id_shop = null)
 {
     $controller = Tools::strReplaceFirst('.php', '', $controller);
     if (!$id_lang) {
         $id_lang = (int) Context::getContext()->language->id;
     }
     if (!is_array($request)) {
         // @FIXME html_entity_decode has been added due to '&' => '%3B' ...
         $request = html_entity_decode($request);
         if ($request_url_encode) {
             $request = urlencode($request);
         }
         parse_str($request, $request);
     }
     if ($id_shop === null) {
         $shop = Context::getContext()->shop;
     } else {
         $shop = new Shop($id_shop);
     }
     $uri_path = Dispatcher::getInstance()->createUrl($controller, $id_lang, $request, false, '', $id_shop);
     $url = $ssl && $this->ssl_enable ? 'https://' : 'http://';
     $url .= $shop->domain . $shop->getBaseURI() . $this->getLangLink($id_lang, null, $id_shop) . ltrim($uri_path, '/');
     return $url;
 }
Exemplo n.º 6
0
 private function getAgileBaseUrl($usevirtual, $id_seller, $ssl, $relative_protocol = false)
 {
     static $force_ssl = null;
     $def_shop_id = (int) Configuration::get('PS_SHOP_DEFAULT');
     $shop = new Shop($def_shop_id);
     if ($usevirtual && $id_seller > 0) {
         $sql = 'SELECT id_shop FROM ' . _DB_PREFIX_ . 'sellerinfo WHERE id_seller=' . (int) $id_seller;
         $id_shop = Db::getInstance()->getValue($sql);
         $shop = new Shop($id_shop);
     }
     if ($ssl === null) {
         if ($force_ssl === null) {
             $force_ssl = Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE');
         }
         $ssl = $force_ssl;
     } else {
         $ssl = $ssl && Configuration::get('PS_SSL_ENABLED');
     }
     if ($relative_protocol) {
         $base = '//' . ($ssl && $this->ssl_enable ? $shop->domain_ssl : $shop->domain);
     } else {
         $base = $ssl && $this->ssl_enable ? 'https://' . $shop->domain_ssl : 'http://' . $shop->domain;
     }
     return $base . $shop->getBaseURI();
 }
Exemplo n.º 7
0
    public function api_3_0_getContent()
    {
        $html = '';
        if (Tools::getValue('PS_GAPI30_CLIENT_ID')) {
            Configuration::updateValue('PS_GAPI30_REQUEST_URI_TMP', dirname($_SERVER['REQUEST_URI']) . '/' . AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'));
            Configuration::updateValue('PS_GAPI30_CLIENT_ID_TMP', trim(Tools::getValue('PS_GAPI30_CLIENT_ID')));
            Configuration::updateValue('PS_GAPI30_CLIENT_SECRET_TMP', trim(Tools::getValue('PS_GAPI30_CLIENT_SECRET')));
            Configuration::updateValue('PS_GAPI_PROFILE_TMP', trim(Tools::getValue('PS_GAPI_PROFILE')));
            // This will redirect the user to Google API authentication page
            $this->api_3_0_authenticate();
        } elseif (Tools::getValue('oauth2callback') == 'error') {
            $html .= $this->displayError('Google API: Access denied');
        } elseif (Tools::getValue('oauth2callback') == 'undefined') {
            $html .= $this->displayError('Something wrong happened with Google API authorization');
        } elseif (Tools::getValue('oauth2callback') == 'success') {
            if ($this->api_3_0_refreshtoken()) {
                $html .= $this->displayConfirmation('Google API Authorization granted');
            } else {
                $html .= $this->displayError('Google API Authorization granted but access token cannot be retrieved');
            }
        }
        $display_slider = true;
        if ($this->api_3_0_isConfigured()) {
            $result_test = $this->api_3_0_requestReportData('', 'ga:visits,ga:uniquePageviews', date('Y-m-d', strtotime('-1 day')), date('Y-m-d', strtotime('-1 day')), null, null, 1, 1);
            if (!$result_test) {
                $html .= $this->displayError('Cannot retrieve test results');
            } else {
                $display_slider = false;
                $html .= $this->displayConfirmation(sprintf($this->l('Yesterday, your store received the visit of %d people for a total of %d unique page views.'), $result_test[0]['metrics']['visits'], $result_test[0]['metrics']['uniquePageviews']));
            }
        }
        if ($display_slider) {
            $shop = new Shop(Shop::getContextShopID(true));
            $authorized_origin = $shop->domain;
            $authorized_redirect = $shop->domain . $shop->getBaseURI() . 'modules/' . $this->name . '/oauth2callback.php';
            $slides = array('Google API - 01 - Start.png' => $this->l('Go to https://code.google.com/apis/console and click the "Create Project" button'), 'Google API - 02 - Services.png' => $this->l('In the "APIS & AUTH > APIs" tab, switch on the Analytics API'), 'Google API - 03 - Terms.png' => $this->l('You may be asked to agree to the Terms of Service of Google APIs and Analytics API'), 'Google API - 04 - Services OK.png' => $this->l('You should now have something like that'), 'Google API - 05 - API Access.png' => $this->l('In the "APIS & AUTH > Credentials" tab, click the first, red, "Create new Client ID" button'), 'Google API - 06 - Create Client ID.png' => sprintf($this->l('Keep "Web application" selected and fill in the "Authorized Javascript Origins" area with "%s" and "%s" then the "Authorized Redirect URI" area with "%s" and "%s".'), 'http://' . $authorized_origin, 'https://' . $authorized_origin, 'http://' . $authorized_redirect, 'https://' . $authorized_redirect) . '
					<br />' . $this->l('Then validate by clicking the "Create client ID" button'), 'Google API - 07 - API Access created.png' => $this->l('You should now have the following screen. Copy/Paste the "Client ID" and "Client secret" into the form below'), 'Google API - 08 - Profile ID.png' => $this->l('Now you need the ID of the Analytics Profile you want to connect. In order to find your Profile ID, connect to the Analytics dashboard, then look at the URL in the address bar. Your Profile ID is the number following a "p", as shown underlined in red on the screenshot'));
            $first_slide = key($slides);
            $html .= '
			<a id="screenshots_button" href="#screenshots"><button class="btn btn-default"><i class="icon-question-sign"></i> How to configure Google Analytics API</button></a>
			<div style="display:none">
				<div id="screenshots" class="carousel slide">
					<ol class="carousel-indicators">';
            $i = 0;
            foreach ($slides as $slide => $caption) {
                $html .= '<li data-target="#screenshots" data-slide-to="' . $i++ . '" ' . ($slide == $first_slide ? 'class="active"' : '') . '></li>';
            }
            $html .= '
					</ol>
					<div class="carousel-inner">';
            foreach ($slides as $slide => $caption) {
                $html .= '
						<div class="item ' . ($slide == $first_slide ? 'active' : '') . '">
							<img src="' . $this->_path . 'screenshots/3.0/' . $slide . '" style="margin:auto">
							<div style="text-align:center;font-size:1.4em;margin-top:10px;font-weight:700">
								' . $caption . '
							</div>
							<div class="clear">&nbsp;</div>
						</div>';
            }
            $html .= '
					</div>
					<a class="left carousel-control" href="#screenshots" data-slide="prev">
						<span class="icon-prev"></span>
					</a>
					<a class="right carousel-control" href="#screenshots" data-slide="next">
						<span class="icon-next"></span>
					</a>
				</div>
			</div>
			<div class="clear">&nbsp;</div>
			<script type="text/javascript">
				$(document).ready(function(){
					$("a#screenshots_button").fancybox();
					$("#screenshots").carousel({interval:false});
					$("ol.carousel-indicators").remove();
				});
			</script>';
        }
        $helper = new HelperOptions($this);
        $helper->id = $this->id;
        $helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->module = $this;
        $fields_options = array('general' => array('title' => $this->l('Google Analytics API v3.0'), 'fields' => $fields = array('PS_GAPI30_CLIENT_ID' => array('title' => $this->l('Client ID'), 'type' => 'text'), 'PS_GAPI30_CLIENT_SECRET' => array('title' => $this->l('Client Secret'), 'type' => 'text'), 'PS_GAPI_PROFILE' => array('title' => $this->l('Profile'), 'type' => 'text')), 'submit' => array('title' => $this->l('Save and Authenticate'))));
        $helper->tpl_vars = array('currentIndex' => $helper->currentIndex);
        return $html . $helper->generateOptions($fields_options);
    }
Exemplo n.º 8
0
 /**
  * Create a link to a product
  *
  * @param mixed $product Product object (can be an ID product, but deprecated)
  * @param string $alias
  * @param string $category
  * @param string $ean13
  * @param int $id_lang
  * @param int $id_shop (since 1.5.0) ID shop need to be used when we generate a product link for a product in a cart
  * @param int $ipa ID product attribute
  * @return string
  */
 public function getProductLink($product, $alias = null, $category = null, $ean13 = null, $id_lang = null, $id_shop = null, $ipa = 0, $force_routes = false)
 {
     $dispatcher = Dispatcher::getInstance();
     if (!$id_lang) {
         $id_lang = Context::getContext()->language->id;
     }
     if (!$id_shop) {
         $shop = Context::getContext()->shop;
     } else {
         $shop = new Shop($id_shop);
     }
     $url = 'http://' . $shop->domain . $shop->getBaseURI() . $this->getLangLink($id_lang);
     if (!is_object($product)) {
         if (is_array($product) && isset($product['id_product'])) {
             $product = new Product($product['id_product'], false, $id_lang);
         } else {
             if (is_numeric($product) || !$product) {
                 $product = new Product($product, false, $id_lang);
             } else {
                 throw new PrestaShopException('Invalid product vars');
             }
         }
     }
     // Set available keywords
     $params = array();
     $params['id'] = $product->id;
     $params['rewrite'] = !$alias ? $product->getFieldByLang('link_rewrite') : $alias;
     $params['ean13'] = !$ean13 ? $product->ean13 : $ean13;
     $params['meta_keywords'] = Tools::str2url($product->getFieldByLang('meta_keywords'));
     $params['meta_title'] = Tools::str2url($product->getFieldByLang('meta_title'));
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'manufacturer')) {
         $params['manufacturer'] = Tools::str2url($product->isFullyLoaded ? $product->manufacturer_name : Manufacturer::getNameById($product->id_manufacturer));
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'supplier')) {
         $params['supplier'] = Tools::str2url($product->isFullyLoaded ? $product->supplier_name : Supplier::getNameById($product->id_supplier));
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'price')) {
         $params['price'] = $product->isFullyLoaded ? $product->price : Product::getPriceStatic($product->id, false, null, 6, null, false, true, 1, false, null, null, null, $product->specificPrice);
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'tags')) {
         $params['tags'] = Tools::str2url($product->getTags($id_lang));
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'category')) {
         $params['category'] = Tools::str2url($product->category);
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'reference')) {
         $params['reference'] = Tools::str2url($product->reference);
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'categories')) {
         $params['category'] = !$category ? $product->category : $category;
         $cats = array();
         foreach ($product->getParentCategories() as $cat) {
             if (!in_array($cat['id_category'], array(1, 2))) {
                 //remove root and home category from the URL
                 $cats[] = $cat['link_rewrite'];
             }
         }
         $params['categories'] = implode('/', $cats);
     }
     $anchor = $ipa ? $product->getAnchor($ipa) : '';
     return $url . $dispatcher->createUrl('product_rule', $id_lang, $params, $force_routes, $anchor);
 }