예제 #1
0
파일: Url.php 프로젝트: maffen/TypoGento
 /**
  * I'm not sure what exactly needs to be done here, will debug later. 
  * 
  * 
  * 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 Varien_Object $product
  * @param Varien_Object $category
  * @param string $parentPath
  * @return string
  * @throws Mage_Core_Exception
  * @todo Test category browsing in typo3
  */
 public function generatePath($type = 'target', $product = null, $category = null, $parentPath = null)
 {
     if (!Mage::getSingleton('Flagbit_Typo3connect/Core')->isEnabled()) {
         return parent::generatePath($type, $product, $category, $parentPath);
     }
     return parent::generatePath($type, $product, $category, $parentPath);
 }
예제 #2
0
 /**
  * Refresh category and childs rewrites
  * Called when reindexing all rewrites and as a reaction on category change that affects rewrites
  *
  * @param int      $categoryId
  * @param int|null $storeId
  * @param bool     $refreshProducts
  *
  * @return Mage_Catalog_Model_Url
  */
 public function refreshCategoryRewrite($categoryId, $storeId = null, $refreshProducts = true)
 {
     if (true === $this->_getHelper()->disableAllCategoriesInUrlRewrite()) {
         return $this;
     }
     return parent::refreshCategoryRewrite($categoryId, $storeId, $refreshProducts);
 }
 /**
  * Write data into enterprise_url_rewrites
  *
  * @param Mage_Catalog_Model_Category $category
  * @param Mage_Core_Model_Store $store
  * @param string $requestPath
  * @param int $valueId
  *
  * @return Mage_Catalog_Model_Category
  */
 protected function _saveRewrite(Mage_Catalog_Model_Category $category, Mage_Core_Model_Store $store, $requestPath, $valueId)
 {
     $this->_uniqueIdentifier = $this->_factory->getHelper('core')->uniqHash();
     $targetPath = $this->_urlModel->generatePath('type', null, $category);
     $rewriteData = array('request_path' => $requestPath, 'target_path' => $targetPath, 'guid' => $this->_uniqueIdentifier, 'is_system' => new Zend_Db_Expr(1), 'identifier' => $requestPath, 'value_id' => $valueId, 'store_id' => $store->getId(), 'entity_type' => Enterprise_Catalog_Model_Category::URL_REWRITE_ENTITY_TYPE);
     $this->_categoryId = $category->getId();
     $this->_storeId = $store->getId();
     $this->_cleanOldUrlRewrite();
     $this->_connection->insert($this->_getTable('enterprise_urlrewrite/url_rewrite'), $rewriteData);
     $this->_refreshRelation();
     $category->setRequestPath($requestPath);
     $this->_changedCategoryIds[$category->getId()] = $category->getId();
     return $category;
 }
 public function getCategoryRequestPath($category, $parentPath)
 {
     /** check for store setting; if YES SHOW PARENT then run parent code - safe for upgrades **/
     $configValue = Mage::getStoreConfig('catalog/seo/category_use_parentcategory', Mage::app()->getStore());
     if (!$configValue) {
         return parent::getCategoryRequestPath($category, $parentPath);
     }
     $storeId = $category->getStoreId();
     $idPath = $this->generatePath('id', null, $category);
     $suffix = $this->getCategoryUrlSuffix($storeId);
     if (isset($this->_rewrites[$idPath])) {
         $this->_rewrite = $this->_rewrites[$idPath];
         $existingRequestPath = $this->_rewrites[$idPath]->getRequestPath();
     }
     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 = Mage::helper('catalog/category')->getCategoryUrlPath($parentPath, true, $category->getStoreId());
     /** If extension setting enabled then reset parentPath to empty
     		http://magento.stackexchange.com/questions/19471/magento-product-url-with-last-subcategory **/
     if ($configValue) {
         $parentPath = '';
     }
     $requestPath = $parentPath . $urlKey . $categoryUrlSuffix;
     if (isset($existingRequestPath) && $existingRequestPath == $requestPath . $suffix) {
         return $existingRequestPath;
     }
     if ($this->_deleteOldTargetPath($requestPath, $idPath, $storeId)) {
         return $requestPath;
     }
     return $this->getUnusedPath($category->getStoreId(), $requestPath, $this->generatePath('id', null, $category));
 }
예제 #5
0
 /**
  * Adds url_path property for non-root category - to ensure that url path is not empty.
  *
  * Sometimes attribute 'url_path' can be empty, because url_path hasn't been generated yet,
  * in this case category is loaded with empty url_path and we should generate it manually.
  *
  * @param Varien_Object $category
  * @return void
  */
 protected function _addCategoryUrlPath($category)
 {
     if (!$category instanceof Varien_Object || $category->getUrlPath()) {
         return;
     }
     // This routine is not intended to be used with root categories,
     // but handle 'em gracefully - ensure them to have empty path.
     if ($category->getLevel() <= 1) {
         $category->setUrlPath('');
         return;
     }
     if (self::$_categoryForUrlPath === null) {
         self::$_categoryForUrlPath = Mage::getModel('catalog/category');
     }
     // Generate url_path
     $urlPath = self::$_categoryForUrlPath->setData($category->getData())->getUrlPath();
     $category->setUrlPath($urlPath);
 }
예제 #6
0
 /**
  * Retrieve resource model, just for phpDoc :)
  *
  * @return Loewenstark_UrlIndexer_Model_Resource_Url
  */
 public function getResource()
 {
     return parent::getResource();
 }
예제 #7
0
 /**
  * Get unique product request path
  *
  * @param   Varien_Object $product
  * @param   Varien_Object $category
  * @return  string
  */
 public function getProductRequestPath($product, $category)
 {
     if (version_compare(Mage::getVersion(), '1.7.0.0', '<')) {
         // The fix below is not compatible with older Magento versions.
         // Then only the shell command of this extension is useful.
         return parent::getProductRequestPath($product, $category);
     } else {
         if ($product->getUrlKey() == '') {
             $urlKey = $this->getProductModel()->formatUrlKey($product->getName());
         } else {
             $urlKey = $this->getProductModel()->formatUrlKey($product->getUrlKey());
         }
         $storeId = $category->getStoreId();
         $suffix = $this->getProductUrlSuffix($storeId);
         $idPath = $this->generatePath('id', $product, $category);
         /**
          * Prepare product base request path
          */
         if ($category->getLevel() > 1) {
             // To ensure, that category has path either from attribute or generated now
             $this->_addCategoryUrlPath($category);
             $categoryUrl = Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath(), false, $storeId);
             $requestPath = $categoryUrl . '/' . $urlKey;
         } else {
             $requestPath = $urlKey;
         }
         if (strlen($requestPath) > self::MAX_REQUEST_PATH_LENGTH + self::ALLOWED_REQUEST_PATH_OVERFLOW) {
             $requestPath = substr($requestPath, 0, self::MAX_REQUEST_PATH_LENGTH);
         }
         $this->_rewrite = null;
         /**
          * Check $requestPath should be unique
          */
         if (isset($this->_rewrites[$idPath])) {
             $this->_rewrite = $this->_rewrites[$idPath];
             $existingRequestPath = $this->_rewrites[$idPath]->getRequestPath();
             if ($existingRequestPath == $requestPath . $suffix) {
                 return $existingRequestPath;
             }
             $existingRequestPath = preg_replace('/' . preg_quote($suffix, '/') . '$/', '', $existingRequestPath);
             /**
              * Check if existing request past can be used
              */
             if ($product->getUrlKey() == '' && !empty($requestPath) && strpos($existingRequestPath, $requestPath) === 0) {
                 $existingRequestPath = preg_replace('/^' . preg_quote($requestPath, '/') . '/', '', $existingRequestPath);
                 if (preg_match('#^-([0-9]+)$#i', $existingRequestPath)) {
                     return $this->_rewrites[$idPath]->getRequestPath();
                 }
             }
             $fullPath = $requestPath . $suffix;
             // PATCH TO FIX MAGENTO BUG THAT DUPLICATES REWRITES WHEN URL_KEY IS EQUAL BETWEEN PRODUCTS
             $pattern = '/^' . preg_quote($requestPath, '/') . '-\\d{1,}$/';
             if (preg_match($pattern, $existingRequestPath)) {
                 $fullPath = $existingRequestPath . $suffix;
             }
             // END OF PATCH
             if ($this->_deleteOldTargetPath($fullPath, $idPath, $storeId)) {
                 return $fullPath;
             }
         }
         /**
          * Check 2 variants: $requestPath and $requestPath . '-' . $productId
          */
         $validatedPath = $this->getResource()->checkRequestPaths(array($requestPath . $suffix, $requestPath . '-' . $product->getId() . $suffix), $storeId);
         if ($validatedPath) {
             return $validatedPath;
         }
         /**
          * Use unique path generator
          */
         return $this->getUnusedPath($storeId, $requestPath . $suffix, $idPath);
     }
 }
예제 #8
0
 public function testGenerateUniqueIdPath()
 {
     $path = $this->_model->generateUniqueIdPath();
     $this->assertNotEmpty($path);
     $this->assertContains('_', $path);
 }
예제 #9
0
파일: Url.php 프로젝트: macosxvn/techheroes
 /**
  * Get unique product request path
  *
  * @param   Varien_Object $product
  * @param   Varien_Object $category
  * @return  string
  */
 public function getProductRequestPath($product, $category)
 {
     if (Mage::getStoreConfig('activo_categoryurlseo/global/enabled') == 0) {
         return parent::getProductRequestPath($product, $category);
     } else {
         if ($product->getUrlKey() == '') {
             $urlKey = $this->getProductModel()->formatUrlKey($product->getName());
         } else {
             $urlKey = $this->getProductModel()->formatUrlKey($product->getUrlKey());
         }
         $storeId = $category->getStoreId();
         $suffix = $this->getProductUrlSuffix($storeId);
         $idPath = $this->generatePath('id', $product, $category);
         /**
          * Prepare product base request path
          */
         if ($category->getLevel() > 1) {
             // To ensure, that category has path either from attribute or generated now
             $this->_addCategoryUrlPath($category);
             $categoryUrl = Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath(), false, $storeId);
             if ($categoryUrl == "") {
                 $requestPath = $urlKey;
             } else {
                 $requestPath = $categoryUrl . '/' . $urlKey;
             }
             $requestPath = str_ireplace('//', '/', $requestPath);
         } else {
             $requestPath = $urlKey;
         }
         if (strlen($requestPath) > self::MAX_REQUEST_PATH_LENGTH + self::ALLOWED_REQUEST_PATH_OVERFLOW) {
             $requestPath = substr($requestPath, 0, self::MAX_REQUEST_PATH_LENGTH);
         }
         $this->_rewrite = null;
         /**
          * Check $requestPath should be unique
          */
         if (isset($this->_rewrites[$idPath])) {
             $this->_rewrite = $this->_rewrites[$idPath];
             $existingRequestPath = $this->_rewrites[$idPath]->getRequestPath();
             $existingRequestPath = str_replace($suffix, '', $existingRequestPath);
             if ($existingRequestPath == $requestPath) {
                 return $requestPath . $suffix;
             }
             /**
              * Check if existing request past can be used
              */
             if ($product->getUrlKey() == '' && !empty($requestPath) && strpos($existingRequestPath, $requestPath) !== false) {
                 $existingRequestPath = str_replace($requestPath, '', $existingRequestPath);
                 if (preg_match('#^-([0-9]+)$#i', $existingRequestPath)) {
                     return $this->_rewrites[$idPath]->getRequestPath();
                 }
             }
             /**
              * check if current generated request path is one of the old paths
              */
             $fullPath = $requestPath . $suffix;
             $finalOldTargetPath = $this->getResource()->findFinalTargetPath($fullPath, $storeId);
             if ($finalOldTargetPath && $finalOldTargetPath == $idPath) {
                 $this->getResource()->deleteRewrite($fullPath, $storeId);
                 return $fullPath;
             }
         }
         /**
          * Check 2 variants: $requestPath and $requestPath . '-' . $productId
          */
         $validatedPath = $this->getResource()->checkRequestPaths(array($requestPath . $suffix, $requestPath . '-' . $product->getId() . $suffix), $storeId);
         if ($validatedPath) {
             return $validatedPath;
         }
         /**
          * Use unique path generator
          */
         return $this->getUnusedPath($storeId, $requestPath . $suffix, $idPath);
     }
 }