Esempio n. 1
0
 /**
  * Retrieve switch currency url
  *
  * @param array $params Additional url params
  * @return string
  */
 public function getSwitchCurrencyUrl($params = array())
 {
     $params = is_array($params) ? $params : array();
     if ($this->_getRequest()->getAlias('rewrite_request_path')) {
         $url = $this->_storeManager->getStore()->getBaseUrl() . $this->_getRequest()->getAlias('rewrite_request_path');
     } else {
         $url = $this->_urlBuilder->getCurrentUrl();
     }
     $params[\Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED] = $this->_coreData->urlEncode($url);
     return $this->_getUrl('directory/currency/switch', $params);
 }
Esempio n. 2
0
 protected function setUp()
 {
     $this->_fixtureCustomerId = 1;
     $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->_customerSession = $this->_objectManager->create('Magento\\Customer\\Model\\Session');
     $this->_coreData = $this->_objectManager->create('Magento\\Core\\Helper\\Data');
     $this->_contextHelper = $this->_objectManager->create('Magento\\Framework\\App\\Helper\\Context');
     $request = $this->_contextHelper->getRequest();
     $request->setParam('data', $this->_coreData->urlEncode($this->_fixtureCustomerId));
     $this->_wishlistHelper = $this->_objectManager->create('Magento\\Rss\\Helper\\WishlistRss', ['context' => $this->_contextHelper, 'customerSession' => $this->_customerSession]);
     $this->_customerSession->loginById($this->_fixtureCustomerId);
 }
Esempio n. 3
0
 /**
  * Retrieve tracking url with params
  *
  * @param  string $key
  * @param  \Magento\Sales\Model\Order|\Magento\Sales\Model\Order\Shipment|\Magento\Sales\Model\Order\Shipment\Track $model
  * @param  string $method Optional - method of a model to get id
  * @return string
  */
 protected function _getTrackingUrl($key, $model, $method = 'getId')
 {
     $urlPart = "{$key}:{$model->{$method}()}:{$model->getProtectCode()}";
     $param = array('hash' => $this->_coreData->urlEncode($urlPart));
     $storeModel = $this->_storeManager->getStore($model->getStoreId());
     return $storeModel->getUrl('shipping/tracking/popup', $param);
 }
Esempio n. 4
0
 /**
  * Retrieve RSS URL
  *
  * @param int|string|null $wishlistId
  * @return string
  */
 public function getRssUrl($wishlistId = null)
 {
     $customer = $this->_getCurrentCustomer();
     if ($customer) {
         $key = $customer->getId() . ',' . $customer->getEmail();
         $params = array('data' => $this->_coreData->urlEncode($key), '_secure' => false);
     }
     if ($wishlistId) {
         $params['wishlist_id'] = $wishlistId;
     }
     return $this->_getUrl('rss/index/wishlist', $params);
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function outputValue($format = \Magento\Customer\Model\Metadata\ElementFactory::OUTPUT_FORMAT_TEXT)
 {
     $output = '';
     if ($this->_value) {
         switch ($format) {
             case \Magento\Customer\Model\Metadata\ElementFactory::OUTPUT_FORMAT_JSON:
                 $output = array('value' => $this->_value, 'url_key' => $this->_coreData->urlEncode($this->_value));
                 break;
         }
     }
     return $output;
 }
Esempio n. 6
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Wishlist/_files/wishlist_with_product_qty_increments.php
  * @magentoAppArea frontend
  */
 public function testCustomerTitle()
 {
     $fixtureCustomerId = 1;
     $this->_customerSession->loginById($fixtureCustomerId);
     /** @var \Magento\Wishlist\Model\Wishlist $wishlist */
     $wishlist = $this->_objectManager->create('Magento\\Wishlist\\Model\\Wishlist')->loadByCustomerId($fixtureCustomerId);
     /** @var \Magento\Framework\App\Helper\Context $contextHelper */
     $contextHelper = $this->_objectManager->create('Magento\\Framework\\App\\Helper\\Context');
     $wishlistHelper = $this->_objectManager->create('Magento\\Wishlist\\Helper\\Rss', ['context' => $contextHelper, 'customerSession' => $this->_customerSession]);
     /** @var \Magento\Catalog\Block\Product\Context $context */
     $contextBlock = $this->_objectManager->create('Magento\\Wishlist\\Block\\Context', ['request' => $contextHelper->getRequest(), 'wishlistHelper' => $wishlistHelper]);
     /** @var \Magento\Framework\App\Request\Http $request */
     $request = $contextHelper->getRequest();
     $request->setParam('wishlist_id', $wishlist->getId());
     $request->setParam('data', $this->_coreData->urlEncode($fixtureCustomerId));
     /** @var \Magento\Wishlist\Block\Rss $block */
     $block = $this->_objectManager->create('Magento\\Wishlist\\Block\\Rss', ['context' => $contextBlock]);
     /** @var \Magento\Framework\Escaper $escaper */
     $escaper = $this->_objectManager->create('Magento\\Framework\\Escaper');
     $expectedSting = '%A' . __("<title><![CDATA[%1 %2's Wishlist]]></title>", $escaper->escapeHtml($this->_customerSession->getCustomerDataObject()->getFirstname()), $escaper->escapeHtml($this->_customerSession->getCustomerDataObject()->getLastname())) . '%A';
     $this->assertStringMatchesFormat($expectedSting, $block->toHtml());
 }
Esempio n. 7
0
 /**
  * Return formated attribute value from entity model
  *
  * @param string $format
  * @return string|array
  */
 public function outputValue($format = \Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_TEXT)
 {
     $output = '';
     $value = $this->getEntity()->getData($this->getAttribute()->getAttributeCode());
     if ($value) {
         switch ($format) {
             case \Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_JSON:
                 $output = array('value' => $value, 'url_key' => $this->_coreData->urlEncode($value));
                 break;
         }
     }
     return $output;
 }
Esempio n. 8
0
 /**
  * Retrieve url for direct adding product to cart
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param array $additional
  * @return string
  */
 public function getAddToCartUrl($product, $additional = array())
 {
     if ($this->hasCustomAddToCartUrl()) {
         return $this->getCustomAddToCartUrl();
     }
     if ($this->getRequest()->getParam('wishlist_next')) {
         $additional['wishlist_next'] = 1;
     }
     $addUrlKey = \Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED;
     $addUrlValue = $this->_urlBuilder->getUrl('*/*/*', array('_use_rewrite' => true, '_current' => true));
     $additional[$addUrlKey] = $this->_coreData->urlEncode($addUrlValue);
     return $this->_cartHelper->getAddUrl($product, $additional);
 }
Esempio n. 9
0
 /**
  * Retrieve url for add product to cart
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param array $additional
  * @return  string
  */
 public function getAddUrl($product, $additional = array())
 {
     $continueUrl = $this->_coreData->urlEncode($this->_urlBuilder->getCurrentUrl());
     $urlParamName = \Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED;
     $routeParams = array($urlParamName => $continueUrl, 'product' => $product->getEntityId());
     if (!empty($additional)) {
         $routeParams = array_merge($routeParams, $additional);
     }
     if ($product->hasUrlDataObject()) {
         $routeParams['_scope'] = $product->getUrlDataObject()->getStoreId();
         $routeParams['_scope_to_url'] = true;
     }
     if ($this->_getRequest()->getRouteName() == 'checkout' && $this->_getRequest()->getControllerName() == 'cart') {
         $routeParams['in_cart'] = 1;
     }
     return $this->_getUrl('checkout/cart/add', $routeParams);
 }
Esempio n. 10
0
 /**
  * Prepare Image insertion declaration for Wysiwyg or textarea(as_is mode)
  *
  * @param string $filename Filename transferred via Ajax
  * @param bool $renderAsTag Leave image HTML as is or transform it to controller directive
  * @return string
  */
 public function getImageHtmlDeclaration($filename, $renderAsTag = false)
 {
     $fileurl = $this->getCurrentUrl() . $filename;
     $mediaUrl = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
     $mediaPath = str_replace($mediaUrl, '', $fileurl);
     $directive = sprintf('{{media url="%s"}}', $mediaPath);
     if ($renderAsTag) {
         $html = sprintf('<img src="%s" alt="" />', $this->isUsingStaticUrlsAllowed() ? $fileurl : $directive);
     } else {
         if ($this->isUsingStaticUrlsAllowed()) {
             $html = $fileurl;
             // $mediaPath;
         } else {
             $directive = $this->_coreData->urlEncode($directive);
             $html = $this->_backendData->getUrl('cms/wysiwyg/directive', array('___directive' => $directive));
         }
     }
     return $html;
 }
Esempio n. 11
0
 /**
  * Initialize review form
  *
  * @return void
  */
 protected function _construct()
 {
     parent::_construct();
     $data = $this->_reviewSession->getFormData(true);
     $data = new \Magento\Framework\Object((array) $data);
     // add logged in customer name as nickname
     if (!$data->getNickname()) {
         $customer = $this->_customerSession->getCustomerDataObject();
         if ($customer && $customer->getId()) {
             $data->setNickname($customer->getFirstname());
         }
     }
     $this->setAllowWriteReviewFlag($this->httpContext->getValue(\Magento\Customer\Helper\Data::CONTEXT_AUTH) || $this->_reviewData->getIsGuestAllowToWrite());
     if (!$this->getAllowWriteReviewFlag()) {
         $queryParam = $this->_coreData->urlEncode($this->getUrl('*/*/*', array('_current' => true)) . '#review-form');
         $this->setLoginLink($this->getUrl('customer/account/login/', array(\Magento\Customer\Helper\Data::REFERER_QUERY_PARAM_NAME => $queryParam)));
     }
     $this->setTemplate('form.phtml')->assign('data', $data)->assign('messages', $this->messageManager->getMessages(true));
 }
Esempio n. 12
0
 /**
  * Retrieve parameters of customer login url
  *
  * @return array
  */
 public function getLoginUrlParams()
 {
     $params = array();
     $referer = $this->_getRequest()->getParam(self::REFERER_QUERY_PARAM_NAME);
     if (!$referer && !$this->_scopeConfig->isSetFlag(self::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) && !$this->_customerSession->getNoReferer()) {
         $referer = $this->_getUrl('*/*/*', array('_current' => true, '_use_rewrite' => true));
         $referer = $this->_coreData->urlEncode($referer);
     }
     if ($referer) {
         $params = array(self::REFERER_QUERY_PARAM_NAME => $referer);
     }
     return $params;
 }
Esempio n. 13
0
 /**
  * Encode list of widget types into query param
  *
  * @param string[]|string $widgets List of widgets
  * @return string Query param value
  */
 public function encodeWidgetsToQuery($widgets)
 {
     $widgets = is_array($widgets) ? $widgets : array($widgets);
     $param = implode(',', $widgets);
     return $this->_coreHelper->urlEncode($param);
 }
Esempio n. 14
0
 /**
  * Get add to wishlist params
  *
  * @param Product $product
  * @return string
  */
 public function getAddToWishlistParams($product)
 {
     $continueUrl = $this->_coreData->urlEncode($this->getUrl('customer/account'));
     $urlParamName = Action::PARAM_NAME_URL_ENCODED;
     $continueUrlParams = array($urlParamName => $continueUrl);
     return $this->_wishlistHelper->getAddParams($product, $continueUrlParams);
 }