Ejemplo n.º 1
0
 /**
  * Implement logic of custom rewrites
  *
  * @return bool
  */
 protected function _rewriteDb()
 {
     if (null === $this->_rewrite->getStoreId() || false === $this->_rewrite->getStoreId()) {
         $this->_rewrite->setStoreId($this->_app->getStore()->getId());
     }
     $requestCases = $this->_getRequestCases();
     $this->_rewrite->loadByRequestPath($requestCases);
     $fromStore = $this->_request->getQuery('___from_store');
     if (!$this->_rewrite->getId() && $fromStore) {
         $stores = $this->_app->getStores(false, true);
         if (!empty($stores[$fromStore])) {
             /** @var $store Mage_Core_Model_Store */
             $store = $stores[$fromStore];
             $fromStoreId = $store->getId();
         } else {
             return false;
         }
         $this->_rewrite->setStoreId($fromStoreId)->loadByRequestPath($requestCases);
         if (!$this->_rewrite->getId()) {
             return false;
         }
         // Load rewrite by id_path
         $currentStore = $this->_app->getStore();
         $this->_rewrite->setStoreId($currentStore->getId())->loadByIdPath($this->_rewrite->getIdPath());
         $this->_setStoreCodeCookie($currentStore->getCode());
         $targetUrl = $currentStore->getBaseUrl() . $this->_rewrite->getRequestPath();
         $this->_sendRedirectHeaders($targetUrl, true);
     }
     if (!$this->_rewrite->getId()) {
         return false;
     }
     $this->_request->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, $this->_rewrite->getRequestPath());
     $this->_processRedirectOptions();
     return true;
 }
Ejemplo n.º 2
0
 public function testLoadByIdPath()
 {
     $this->_model->setStoreId(Mage::app()->getDefaultStoreView()->getId())->setRequestPath('product1.html')->setTargetPath('catalog/product/view/id/1')->setIdPath('product/1')->setIsSystem(1)->setOptions('RP')->save();
     try {
         $read = Mage::getModel('Mage_Core_Model_Url_Rewrite');
         $read->setStoreId(Mage::app()->getDefaultStoreView()->getId())->loadByIdPath('product/1');
         $this->assertEquals($this->_model->getStoreId(), $read->getStoreId());
         $this->assertEquals($this->_model->getRequestPath(), $read->getRequestPath());
         $this->assertEquals($this->_model->getTargetPath(), $read->getTargetPath());
         $this->assertEquals($this->_model->getIdPath(), $read->getIdPath());
         $this->assertEquals($this->_model->getIsSystem(), $read->getIsSystem());
         $this->assertEquals($this->_model->getOptions(), $read->getOptions());
         $this->_model->delete();
     } catch (Exception $e) {
         $this->_model->delete();
         throw $e;
     }
 }
Ejemplo n.º 3
0
 public function saveRewrite(Mage_Core_Model_Url_Rewrite $rewrite)
 {
     if (!$rewrite->getId()) {
         $old = Mage::getModel('core/url_rewrite')->setStoreId($rewrite->getStoreId())->loadByIdPath($rewrite->getIdPath());
         if (!$old) {
             $old->loadByRequestPath($rewrite->getRequestPath());
         }
         if ($old) {
             $rewrite->setId($old->getId());
         }
     }
     $rewrite->save();
     $this->_rewrites[$rewrite->getStoreId()][$rewrite->getIdPath()] = $rewrite;
     $this->_paths[$rewrite->getStoreId()][$rewrite->getRequestPath()] = $rewrite->getIdPath();
     return $this;
 }