Exemplo n.º 1
0
 /**
  * @return array
  */
 protected function getItems()
 {
     $items = [];
     foreach ($this->helper->getItemCollection() as $item) {
         $items[] = ['id' => $item->getId(), 'product_url' => $this->productUrl->getUrl($item), 'name' => $this->outputHelper->productAttribute($item, $item->getName(), 'name'), 'remove_url' => $this->helper->getPostDataRemove($item)];
     }
     return $items;
 }
Exemplo n.º 2
0
 /**
  * @magentoAppArea frontend
  */
 public function testGetUrl()
 {
     $repository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\ProductRepository');
     $product = $repository->get('simple');
     $this->assertStringEndsWith('simple-product.html', $this->_model->getUrl($product));
     $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $product->setId(100);
     $this->assertContains('catalog/product/view/id/100/', $this->_model->getUrl($product));
 }
Exemplo n.º 3
0
 public function testGetUrl()
 {
     /** @var $product \Magento\Catalog\Model\Product */
     $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $product->load(1);
     $this->assertStringEndsWith('simple-product.html', $this->_model->getUrl($product));
     $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $product->setId(100);
     $this->assertStringEndsWith('catalog/product/view/id/100/', $this->_model->getUrl($product));
 }
Exemplo n.º 4
0
 /**
  * @dataProvider getUrlDataProvider
  * @covers \Magento\Catalog\Model\Product\Url::getUrl
  * @covers \Magento\Catalog\Model\Product\Url::getUrlInStore
  * @covers \Magento\Catalog\Model\Product\Url::getProductUrl
  *
  * @param $getUrlMethod
  * @param $routePath
  * @param $requestPathProduct
  * @param $storeId
  * @param $categoryId
  * @param $routeParams
  * @param $routeParamsUrl
  * @param $productId
  * @param $productUrlKey
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function testGetUrl($getUrlMethod, $routePath, $requestPathProduct, $storeId, $categoryId, $routeParams, $routeParamsUrl, $productId, $productUrlKey)
 {
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['getStoreId', 'getEntityId', 'getId', 'getUrlKey', 'setRequestPath', 'hasUrlDataObject', 'getRequestPath', 'getCategoryId', 'getDoNotUseCategoryId', '__wakeup'])->getMock();
     $product->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId));
     $product->expects($this->any())->method('getCategoryId')->will($this->returnValue($categoryId));
     $product->expects($this->any())->method('getRequestPath')->will($this->returnValue($requestPathProduct));
     $product->expects($this->any())->method('setRequestPath')->with(false)->will($this->returnSelf());
     $product->expects($this->any())->method('getId')->will($this->returnValue($productId));
     $product->expects($this->any())->method('getUrlKey')->will($this->returnValue($productUrlKey));
     $this->url->expects($this->any())->method('setScope')->with($storeId)->will($this->returnSelf());
     $this->url->expects($this->any())->method('getUrl')->with($routePath, $routeParamsUrl)->will($this->returnValue($requestPathProduct));
     $this->urlFinder->expects($this->any())->method('findOneByData')->will($this->returnValue(false));
     switch ($getUrlMethod) {
         case 'getUrl':
             $this->assertEquals($requestPathProduct, $this->model->getUrl($product, $routeParams));
             break;
         case 'getUrlInStore':
             $this->assertEquals($requestPathProduct, $this->model->getUrlInStore($product, $routeParams));
             break;
         case 'getProductUrl':
             $this->assertEquals($requestPathProduct, $this->model->getProductUrl($product, true));
             $this->sidResolver->expects($this->once())->method('getUseSessionInUrl')->will($this->returnValue(true));
             $this->assertEquals($requestPathProduct, $this->model->getProductUrl($product, null));
             break;
     }
 }
 /**
  * @param array $rowData
  * @return string
  */
 protected function getUrlKey($rowData)
 {
     if (!empty($rowData[self::URL_KEY])) {
         $this->productUrlKeys[$rowData[self::COL_SKU]] = $rowData[self::URL_KEY];
     }
     $urlKey = !empty($this->productUrlKeys[$rowData[self::COL_SKU]]) ? $this->productUrlKeys[$rowData[self::COL_SKU]] : $this->productUrl->formatUrlKey($rowData[self::COL_NAME]);
     return $urlKey;
 }
Exemplo n.º 6
0
 public function __construct(UrlFactory $urlFactory, StoreManagerInterface $storeManager, FilterManager $filter, SidResolverInterface $sidResolver, UrlFinderInterface $urlFinder, ObjectManagerInterface $objectManager, array $data = [])
 {
     $this->objectManager = $objectManager;
     parent::__construct($urlFactory, $storeManager, $filter, $sidResolver, $urlFinder, $data);
 }
Exemplo n.º 7
0
 /**
  * Generate either id path, request path or target path for product and/or category
  *
  * For generating id or system path, either product or category is required
  * For generating request path - category is required
  * $parentPath used only for generating category path
  *
  * @param string $type
  * @param \Magento\Framework\Object $product
  * @param \Magento\Framework\Object $category
  * @param string $parentPath
  * @return string
  * @throws \Magento\Framework\Model\Exception
  */
 public function generatePath($type = 'target', $product = null, $category = null, $parentPath = null)
 {
     if (!$product && !$category) {
         throw new \Magento\Framework\Model\Exception(__('Please specify either a category or a product, or both.'));
     }
     // generate id_path
     if ('id' === $type) {
         if (!$product) {
             return 'category/' . $category->getId();
         }
         if ($category && $category->getLevel() > 1) {
             return 'product/' . $product->getId() . '/' . $category->getId();
         }
         return 'product/' . $product->getId();
     }
     // generate request_path
     if ('request' === $type) {
         // for category
         if (!$product) {
             if ($category->getUrlKey() == '') {
                 $urlKey = $this->getCategoryModel()->formatUrlKey($category->getName());
             } else {
                 $urlKey = $this->getCategoryModel()->formatUrlKey($category->getUrlKey());
             }
             $categoryUrlSuffix = $this->getCategoryUrlSuffix($category->getStoreId());
             if (null === $parentPath) {
                 $parentPath = $this->getResource()->getCategoryParentPath($category);
             } elseif ($parentPath == '/') {
                 $parentPath = '';
             }
             $parentPath = $this->_catalogCategory->getCategoryUrlPath($parentPath, true, $category->getStoreId());
             return $this->getUnusedPath($category->getStoreId(), $parentPath . $urlKey . $categoryUrlSuffix, $this->generatePath('id', null, $category), $urlKey);
         }
         // for product & category
         if (!$category) {
             throw new \Magento\Framework\Model\Exception(__('A category object is required for determining the product request path.'));
         }
         if ($product->getUrlKey() == '') {
             $urlKey = $this->productUrl->formatUrlKey($product->getName());
         } else {
             $urlKey = $this->productUrl->formatUrlKey($product->getUrlKey());
         }
         $productUrlSuffix = $this->getProductUrlSuffix($category->getStoreId());
         if ($category->getLevel() > 1) {
             // To ensure, that category has url path either from attribute or generated now
             $this->_addCategoryUrlPath($category);
             $categoryUrl = $this->_catalogCategory->getCategoryUrlPath($category->getUrlPath(), false, $category->getStoreId());
             return $this->getUnusedPath($category->getStoreId(), $categoryUrl . '/' . $urlKey . $productUrlSuffix, $this->generatePath('id', $product, $category), $urlKey);
         }
         // for product only
         return $this->getUnusedPath($category->getStoreId(), $urlKey . $productUrlSuffix, $this->generatePath('id', $product), $urlKey);
     }
     // generate target_path
     if (!$product) {
         return 'catalog/category/view/id/' . $category->getId();
     }
     if ($category && $category->getLevel() > 1) {
         return 'catalog/product/view/id/' . $product->getId() . '/category/' . $category->getId();
     }
     return 'catalog/product/view/id/' . $product->getId();
 }