Exemplo n.º 1
0
 public function testGetUrl()
 {
     $product = new Mage_Catalog_Model_Product();
     $product->load(1);
     $this->assertStringEndsWith('simple-product.html', $this->_model->getUrl($product));
     $product = new Mage_Catalog_Model_Product();
     $product->setId(100);
     $this->assertStringEndsWith('catalog/product/view/id/100/', $this->_model->getUrl($product));
 }
 public function getUrl(Mage_Catalog_Model_Product $product, $params = array())
 {
     if (Mage::getVersion() >= 1.8) {
         $product->setData('url', '');
     }
     return parent::getUrl($product, $params);
 }
Exemplo n.º 3
0
 /**
  * Retrieve Product URL using UrlDataObject
  *
  * @param Mage_Catalog_Model_Product $product
  * @param array $params
  * @return string
  */
 public function getUrl(Mage_Catalog_Model_Product $product, $params = array())
 {
     if (!Mage::helper('ascurl')->useCanonicalUrl()) {
         return parent::getUrl($product, $params);
     }
     $routePath = '';
     $routeParams = $params;
     $storeId = $product->getStoreId();
     if (isset($params['_ignore_category'])) {
         unset($params['_ignore_category']);
         $categoryId = null;
     } else {
         $categoryId = $product->getCategoryId() && !$product->getDoNotUseCategoryId() ? $product->getCategoryId() : null;
     }
     if (!$categoryId) {
         $product = Mage::getModel('catalog/product')->load($product->getId());
         $categoryId = Mage::helper('ascurl')->getCategoryIdAsc($product);
     }
     if ($product->hasUrlDataObject()) {
         $requestPath = $product->getUrlDataObject()->getUrlRewrite();
         $routeParams['_store'] = $product->getUrlDataObject()->getStoreId();
     } else {
         $requestPath = $product->getRequestPath();
         if (empty($requestPath)) {
             $idPath = sprintf('product/%d', $product->getEntityId());
             if ($categoryId) {
                 $idPath = sprintf('%s/%d', $idPath, $categoryId);
             }
             $rewrite = $this->getUrlRewrite();
             $rewrite->setStoreId($storeId)->loadByIdPath($idPath);
             if ($rewrite->getId()) {
                 $requestPath = $rewrite->getRequestPath();
                 $product->setRequestPath($requestPath);
             }
         }
     }
     if (isset($routeParams['_store'])) {
         $storeId = Mage::app()->getStore($routeParams['_store'])->getId();
     }
     if ($storeId != Mage::app()->getStore()->getId()) {
         $routeParams['_store_to_url'] = true;
     }
     if (!empty($requestPath)) {
         $routeParams['_direct'] = $requestPath;
     } else {
         $routePath = 'catalog/product/view';
         $routeParams['id'] = $product->getId();
         $routeParams['s'] = $product->getUrlKey();
         if ($categoryId) {
             $routeParams['category'] = $categoryId;
         }
     }
     // reset cached URL instance GET query params
     if (!isset($routeParams['_query'])) {
         $routeParams['_query'] = array();
     }
     return $this->getUrlInstance()->setStore($storeId)->getUrl($routePath, $routeParams);
 }
Exemplo n.º 4
0
 public function testGetUrl()
 {
     /** @var $product Mage_Catalog_Model_Product */
     $product = Mage::getModel('Mage_Catalog_Model_Product');
     $product->load(1);
     $this->assertStringEndsWith('simple-product.html', $this->_model->getUrl($product));
     $product = Mage::getModel('Mage_Catalog_Model_Product');
     $product->setId(100);
     $this->assertStringEndsWith('catalog/product/view/id/100/', $this->_model->getUrl($product));
 }