/**
  * Transforms an object (product) to a string (number).
  *
  * @param  product|null $product
  * @return string
  */
 public function transform($product)
 {
     if (null === $product) {
         return '';
     }
     return $product->getId();
 }
Example #2
0
 /**
  * Rewriting this method to output new urls.
  * Checks if a rewrite already exists, otherwise creates it.
  * 
  * @param product $product
  * @param category $category
  * @param array $params
  */
 public function getReviewsUrl($product, $category = null, $params = array())
 {
     $routePath = '';
     $routeParams = $params;
     $storeId = $product->getStoreId();
     if (!$storeId) {
         $storeId = Mage::app()->getStore()->getId();
         $product->setStoreId($storeId);
     }
     $categoryId = $product->getCategoryId() && !$product->getDoNotUseCategoryId() ? $product->getCategoryId() : null;
     $idPath = sprintf('reviews/%d', $product->getId());
     //if ($categoryId) {
     //     $idPath = sprintf('%s/%d', $idPath, $categoryId);
     //}
     $rewrite = $this->getUrlRewrite();
     $rewrite->setStoreId($storeId)->loadByIdPath($idPath);
     $oldRequestPath = $product->getRequestPath();
     if ($rewrite->getId()) {
         // REWRITE RULE EXISTS
         $requestPath = $rewrite->getRequestPath();
         $product->setRequestPath($requestPath);
     } else {
         // CREATE REWRITE RULE
         $model = Mage::getModel('reviewsearchfriendlyurls/url');
         $requestPath = $model->addUrlRewrite($product);
     }
     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();
     }
     $url = $this->getUrlInstance()->setStore($storeId)->getUrl($routePath, $routeParams);
     $product->setRequestPath($oldRequestPath);
     return $url;
 }
Example #3
0
 /**
  * Delete
  */
 public function deleteOne(product $p)
 {
     try {
         dibi::query('DELETE FROM [:prefix:products]', 'WHERE [id] = %i', $p->getId(), 'LIMIT 1');
         dibi::query('DELETE FROM [:prefix:pages]', 'WHERE [nice_name] = %s', $p->getNiceName(), 'LIMIT 1');
         //<fulltext>
         foreach (fulltext::index()->termDocs(new Zend_Search_Lucene_Index_Term($p->getId(), 'id')) as $id) {
             fulltext::index()->delete($id);
         }
         fulltext::dirty($p->getId(), FALSE);
         //</fulltext>
         return TRUE;
     } catch (Exception $e) {
         return FALSE;
     }
 }