Ejemplo n.º 1
0
 public static function inRestrictProducts(Mage_Catalog_Model_Product $oProduct)
 {
     $product_disabled = false;
     $restrict_groups = Mage::getStoreConfig('zeo_actions_setting/product_price/customer_groups');
     $restrict_groups = trim($restrict_groups);
     $restrict_groups = trim($restrict_groups, ",");
     if ($restrict_groups != "") {
         $restrict_groups_array = explode(",", $restrict_groups);
         $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
         if (in_array($groupId, $restrict_groups_array)) {
             return true;
         }
     }
     $restrict_categories = Mage::getStoreConfig('zeo_actions_setting/product_price/catalog_categories');
     $restrict_categories = trim($restrict_categories);
     $restrict_categories = trim($restrict_categories, ",");
     if ($restrict_categories != "") {
         $restrict_categories_array = explode(",", $restrict_categories);
         $product_categpries = $oProduct->getCategoryIds();
         $final_cats = array_intersect($restrict_categories_array, $product_categpries);
         if (count($final_cats) > 0) {
             return true;
         }
     }
     return $product_disabled;
 }
Ejemplo n.º 2
0
 /**
  * Gets sorted product tags templates congiguration
  *
  * @param Mage_Catalog_Model_Product $product
  * @return array sorted configs 
  */
 public function getConfigByProduct($product)
 {
     $config = array();
     $ids = $product->getCategoryIds();
     if (!$ids) {
         return array();
     }
     if (is_null($this->_configs)) {
         $storeId = Mage::app()->getStore()->getId();
         $this->_configs = Mage::getModel('ammeta/config')->getCollection()->addFieldToFilter('stores', array('like' => "%,{$storeId},%"))->load();
     }
     if (!count($this->_configs)) {
         return array();
     }
     $ids = array_reverse($ids);
     // set the most specific first
     foreach ($ids as $id) {
         foreach ($this->_configs as $item) {
             if ($item->getCategoryId() == $id) {
                 $config[] = $item;
                 break;
             }
         }
     }
     return $config;
 }
Ejemplo n.º 3
0
 public function getItemBaseInfo()
 {
     $helper = Mage::helper('catalog/image');
     $helper->init($this->product, $this->getProductImageType())->keepAspectRatio($this->_keepAspectRatio)->keepFrame($this->_keepFrame);
     $this->item['item_id'] = $this->product->getId();
     $this->item['item_title'] = $this->product->getName();
     $this->item['item_url'] = $this->product->getProductUrl();
     $this->item['cid'] = $this->product->getCategoryIds();
     $this->item['qty'] = $this->product->getStockItem()->getQty();
     $this->item['thumbnail_pic_url'] = (string) $helper->resize($this->thumbnail_with, $this->thumbnail_height);
     $this->item['main_pic_url'] = (string) $helper->resize($this->main_with, $this->main_height);
     $this->item['is_virtual'] = $this->product->isVirtual();
     $this->item['item_status'] = $this->product->isSaleable() ? 'instock' : 'outofstock';
     if (!$this->product->getRatingSummary()) {
         Mage::getModel('review/review')->getEntitySummary($this->product, Mage::app()->getStore()->getId());
     }
     $this->item['allow_add_to_cart'] = !$this->HasOptions();
     $this->item['rating_score'] = round((int) $this->product->getRatingSummary()->getRatingSummary() / 20);
     $this->item['rating_count'] = $this->product->getRatingSummary()->getReviewsCount();
     $this->item['sales_type'] = $this->product->isInStock() ? 'stock' : 'distribute';
     $this->item['qty_min_unit'] = 1;
     $stockItem = $this->product->getStockItem();
     if ($stockItem) {
         if ($stockItem->getMinSaleQty() && $stockItem->getMinSaleQty() > 0) {
             $this->item['qty_min_unit'] = $stockItem->getMinSaleQty();
         }
     }
     $this->item['item_type'] = $this->product->getTypeId();
     return $this->item;
 }
Ejemplo n.º 4
0
 /**
  * Check if product is inside of the category
  * 
  * @param  Mage_Catalog_Model_Product   $product  
  * @param  Mage_Catalog_Model_Category  $category 
  * @return boolean
  */
 private function _isProductInCategory($product, $category)
 {
     $categoryIds = $product->getCategoryIds();
     $categoryId = $category->getId();
     if (in_array($categoryId, $categoryIds)) {
         return true;
     }
     return false;
 }
Ejemplo n.º 5
0
 public function getProductCategoryName(Mage_Catalog_Model_Product $product)
 {
     $productCategories = $product->getCategoryIds();
     if (!count($productCategories)) {
         return;
     }
     $tmpCategory = Mage::getModel('catalog/category')->load($productCategories[0]);
     //echo $tmpCategory->getId();
     return $tmpCategory->getName();
 }
 /**
  * Retrieve an array of category_ids that are associated with the product
  *
  * @param Mage_Catalog_Model_Product $product
  * @return array
  */
 public function getAssociatedCategoryIds(Mage_Catalog_Model_Product $product)
 {
     $wpCategoryIds = $this->_getAssociatedWpEntityIds($product->getId(), 'category', 'category');
     if ($categoryIds = $product->getCategoryIds()) {
         foreach ($categoryIds as $categoryId) {
             $wpCategoryIds = array_merge($wpCategoryIds, $this->_getAssociatedWpEntityIds($categoryId, 'wp_category', 'category', 'category_id', 'category'));
         }
     }
     return array_unique($wpCategoryIds);
 }
Ejemplo n.º 7
0
 public function getProductActiveCategories(Mage_Catalog_Model_Product $product, $storeId = null)
 {
     $activeCategories = array();
     foreach ($product->getCategoryIds() as $categoryId) {
         if ($this->isCategoryActive($categoryId, $storeId)) {
             $activeCategories[] = $categoryId;
         }
     }
     return $activeCategories;
 }
Ejemplo n.º 8
0
 public function testGetCategoryIds()
 {
     // none
     /** @var $model Mage_Catalog_Model_Product */
     $model = Mage::getModel('Mage_Catalog_Model_Product');
     $this->assertEquals(array(), $model->getCategoryIds());
     // fixture
     $this->_model->setId(1);
     $this->assertEquals(array(2, 3, 4), $this->_model->getCategoryIds());
 }
Ejemplo n.º 9
0
 public function getReverbCategoryObjectsByProduct(Mage_Catalog_Model_Product $magentoProduct)
 {
     $magento_category_ids = $magentoProduct->getCategoryIds();
     $reverb_category_uuids = Mage::getResourceSingleton('reverbSync/category_reverb_magento_xref')->getReverbCategoryUuidsByMagentoCategoryIds($magento_category_ids);
     if (empty($reverb_category_uuids)) {
         // Return an empty array
         return array();
     }
     $reverb_category_uuids = array_unique($reverb_category_uuids);
     $reverbCategoryCollection = Mage::getModel('reverbSync/category_reverb')->getCollection()->addCategoryUuidFilter($reverb_category_uuids);
     return $reverbCategoryCollection->getItems();
 }
Ejemplo n.º 10
0
 /**
  * Should return list of tags to clean
  *
  * @param Mage_Catalog_Model_Product $object
  * @return string[]|string
  */
 protected function _collectTags($object)
 {
     // Clear category cache for new products
     if ($this->_isForUpdate && !$object->getId()) {
         $result = array();
         foreach ($object->getCategoryIds() as $categoryId) {
             $result[] = EcomDev_Varnish_Model_Processor_Category::TAG_PREFIX . $categoryId;
         }
         return $result;
     }
     return self::TAG_PREFIX . $object->getId();
 }
Ejemplo n.º 11
0
 /**
  * Validate that the category of a give product is activated in the module
  *
  * @param Mage_Catalog_Model_Product $oProduct
  * @return bool
  */
 public function isCategoryActiveByProduct(Mage_Catalog_Model_Product $oProduct)
 {
     $aCurrentCategories = $oProduct->getCategoryIds();
     $aLinkedProductIds = array();
     if ($oProduct->isSuper()) {
         $aLinkedProductIds = $this->getChildrenAndParentIds($oProduct);
     }
     if (!empty($aLinkedProductIds)) {
         $aCurrentCategories = $this->getAllCategoryIds($aLinkedProductIds, $aCurrentCategories);
     }
     if (!is_array($aCurrentCategories)) {
         $aCurrentCategories = array($aCurrentCategories);
     }
     return $this->hasActiveCategory($aCurrentCategories);
 }
Ejemplo n.º 12
0
 private function processCategoriesActions(Mage_Catalog_Model_Product $product)
 {
     $productCategories = $product->getCategoryIds();
     $categoriesByWebsite = array(0 => $productCategories);
     foreach ($product->getWebsiteIds() as $websiteId) {
         $categoriesByWebsite[$websiteId] = $productCategories;
     }
     /** @var Ess_M2ePro_Model_Listing_Auto_Actions_Mode_Category $autoActionsCategory */
     $autoActionsCategory = Mage::getModel('M2ePro/Listing_Auto_Actions_Mode_Category');
     $autoActionsCategory->setProduct($product);
     foreach ($categoriesByWebsite as $websiteId => $categoryIds) {
         foreach ($categoryIds as $categoryId) {
             $autoActionsCategory->synchWithAddedCategoryId($categoryId, $websiteId);
         }
     }
 }
Ejemplo n.º 13
0
 /**
  * @param Mage_Catalog_Model_Product $product
  * @return boolean
  */
 protected function _changeUrlKey(Mage_Catalog_Model_Product &$product)
 {
     if ($product->getCategoryId() || !$this->_getHelper()->isUrlRewriteEnable()) {
         return false;
     }
     //if category already exist or rewrite categories is disabled
     $categoryIds = $product->getCategoryIds();
     $categoryId = null;
     $product->setData("request_path", null);
     /** Process categories if they exists */
     if (is_array($categoryIds) && count($categoryIds)) {
         $categoryId = $categoryIds[count($categoryIds) - 1];
         //get the last element
     }
     return $this->_getUrlModel()->getProductUrl($product, null, $categoryId);
 }
Ejemplo n.º 14
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Varien_Gdata_Gshopping_Entry $entry
  * @return Varien_Gdata_Gshopping_Entry
  */
 public function convertAttribute($product, $entry)
 {
     $productCategories = $product->getCategoryIds();
     // TODO: set Default value for product_type attribute if product isn't assigned for any category
     $value = 'Shop';
     if (!empty($productCategories)) {
         $category = Mage::getModel('Mage_Catalog_Model_Category')->load(array_shift($productCategories));
         $breadcrumbs = array();
         foreach ($category->getParentCategories() as $cat) {
             $breadcrumbs[] = $cat->getName();
         }
         $value = implode(' > ', $breadcrumbs);
     }
     $this->_setAttribute($entry, 'product_type', self::ATTRIBUTE_TYPE_TEXT, $value);
     return $entry;
 }
Ejemplo n.º 15
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Google_Service_ShoppingContent_Product $shoppingProduct
  * @return Google_Service_ShoppingContent_Product
  */
 public function convertAttribute($product, $shoppingProduct)
 {
     $productCategories = $product->getCategoryIds();
     // TODO: set Default value for product_type attribute if product isn't assigned for any category
     $value = 'Shop';
     if (!empty($productCategories)) {
         $category = Mage::getModel('catalog/category')->load(array_shift($productCategories));
         $breadcrumbs = array();
         foreach ($category->getParentCategories() as $cat) {
             $breadcrumbs[] = $cat->getName();
         }
         $value = implode(' > ', $breadcrumbs);
         Mage::log($value);
     }
     $shoppingProduct->setProductType($value);
     return $shoppingProduct;
 }
Ejemplo n.º 16
0
 /**
  * 
  * @param Mage_Catalog_Model_Product $product
  */
 public function setCategory($product)
 {
     $collection = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect(array('parent_id'))->addAttributeToFilter('entity_id', array('in' => $product->getCategoryIds()))->addAttributeToFilter('path', array('like' => $this->getRootCategoryPath() . '/%'))->addAttributeToFilter('is_active', 1)->addOrder('level', Varien_Data_Collection_Db::SORT_ORDER_DESC)->addOrder('include_in_menu', Varien_Data_Collection_Db::SORT_ORDER_DESC)->setPageSize(1)->setCurPage(1);
     if (!$product->getSkipEvent()) {
         Mage::dispatchEvent('mp_breadcrumb_category_collection', array('product' => $product, 'collection' => $collection));
     }
     $collection->load();
     if ($collection->count() > 0) {
         $id = $collection->getFirstItem()->getId();
         if ($product->canBeShowInCategory($id)) {
             $category = Mage::getModel('catalog/category')->load($id);
             /* @var $category Mage_Catalog_Model_Category */
             Mage::register('current_category', $category);
             $product->canBeShowInCategory($category->getId());
         }
     }
 }
Ejemplo n.º 17
0
 private function processCategoriesActions(Mage_Catalog_Model_Product $magentoProduct)
 {
     $productCategories = $magentoProduct->getCategoryIds();
     $categoriesByWebsite = array(0 => $productCategories);
     foreach ($magentoProduct->getWebsiteIds() as $websiteId) {
         $categoriesByWebsite[$websiteId] = $productCategories;
     }
     /** @var Ess_M2ePro_Model_Observer_Category $categoryObserverModel */
     $categoryObserverModel = Mage::getModel('M2ePro/Observer_Category');
     /** @var Ess_M2ePro_Model_Observer_Ebay_Category $ebayCategoryObserver */
     $ebayCategoryObserver = Mage::getModel('M2ePro/Observer_Ebay_Category');
     foreach ($categoriesByWebsite as $websiteId => $categoriesIds) {
         foreach ($categoriesIds as $categoryId) {
             $categoryObserverModel->synchProductWithAddedCategoryId($magentoProduct, $categoryId, $websiteId);
             $ebayCategoryObserver->synchProductWithAddedCategoryId($magentoProduct, $categoryId, $websiteId);
         }
     }
 }
Ejemplo n.º 18
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Google_Service_ShoppingContent_Product $shoppingProduct
  * @return Google_Service_ShoppingContent_Product
  */
 public function convertAttribute($product, $shoppingProduct)
 {
     $productCategories = $product->getCategoryIds();
     $value = 'Shop';
     if (!empty($productCategories)) {
         $category = Mage::getModel('catalog/category')->load(array_shift($productCategories));
         $breadcrumbs = array();
         foreach ($category->getParentCategories() as $cat) {
             $breadcrumbs[] = $cat->getName();
         }
         $value = implode(' > ', $breadcrumbs);
         if (!count($breadcrumbs)) {
             $value = $category->getName();
         }
     }
     $shoppingProduct->setProductType($value);
     return $shoppingProduct;
 }
Ejemplo n.º 19
0
 /**
  * Retrieve a collection of post's associated with the given product
  *
  * @param Mage_Catalog_Model_Product $product
  * @return false|Fishpig_Wordpress_Model_Resource_Post_Collection_Abstract
  */
 public function getAssociatedPostsByProduct(Mage_Catalog_Model_Product $product)
 {
     if (!$product instanceof Mage_Catalog_Model_Product) {
         return false;
     }
     $associations = array_keys($this->getAssociations('product/post', $product->getId()));
     $categoryAssociations = array_keys($this->getAssociations('product/category', $product->getId()));
     $associations = array_merge($associations, $this->_convertWpCategoryIds($categoryAssociations));
     foreach ($product->getCategoryIds() as $categoryId) {
         $associations = array_merge($associations, array_keys($this->getAssociations('category/post', $categoryId)));
         $categoryAssociations = array_keys($this->getAssociations('category/category', $categoryId));
         $associations = array_merge($associations, $this->_convertWpCategoryIds($categoryAssociations));
     }
     if (count($associations) > 0) {
         return Mage::getResourceModel('wordpress/post_collection')->addFieldToFilter('ID', array('IN' => $associations))->addIsPublishedFilter();
     }
     return false;
 }
Ejemplo n.º 20
0
 /**
  * @param Mage_Catalog_Model_Product $product the product model
  * @return string URL
  */
 public function getUrl($product)
 {
     // New url rewrites with enterprise 1.13
     $magentoVersion = Mage::getVersion();
     if (version_compare($magentoVersion, '1.13', '>=')) {
         $requestPath = $product->getUrlKey();
         if ($requestPath) {
             return Mage::getUrl('', array('_direct' => $requestPath));
         }
     }
     $rewrite = null;
     if ($categories = $product->getCategoryIds()) {
         $rewrite = Mage::getModel('catalog/url')->getResource()->getRewriteByIdPath('product/' . $product->getId() . '/' . reset($categories), 1);
     }
     if (!$rewrite) {
         $rewrite = Mage::getModel('catalog/url')->getResource()->getRewriteByIdPath('product/' . $product->getId(), 1);
     }
     return Mage::getUrl('', array('_direct' => $rewrite->getRequestPath()));
 }
 /**
  * Create Product array from Mage_Catalog_Model_Product
  *
  * @param Mage_Catalog_Model_Product $product
  * @return array
  */
 public function getProductData(Mage_Catalog_Model_Product $product)
 {
     try {
         $data = array('url' => $product->getProductUrl(), 'title' => htmlspecialchars($product->getName()), 'spider' => 1, 'price' => $product->getPrice(), 'description' => urlencode($product->getDescription()), 'tags' => htmlspecialchars($product->getMetaKeyword()), 'images' => array(), 'vars' => array('sku' => $product->getSku(), 'storeId' => '', 'typeId' => $product->getTypeId(), 'status' => $product->getStatus(), 'categoryId' => $product->getCategoryId(), 'categoryIds' => $product->getCategoryIds(), 'websiteIds' => $product->getWebsiteIds(), 'storeIds' => $product->getStoreIds(), 'groupPrice' => $product->getGroupPrice(), 'formatedPrice' => $product->getFormatedPrice(), 'calculatedFinalPrice' => $product->getCalculatedFinalPrice(), 'minimalPrice' => $product->getMinimalPrice(), 'specialPrice' => $product->getSpecialPrice(), 'specialFromDate' => $product->getSpecialFromDate(), 'specialToDate' => $product->getSpecialToDate(), 'relatedProductIds' => $product->getRelatedProductIds(), 'upSellProductIds' => $product->getUpSellProductIds(), 'getCrossSellProductIds' => $product->getCrossSellProductIds(), 'isSuperGroup' => $product->isSuperGroup(), 'isGrouped' => $product->isGrouped(), 'isConfigurable' => $product->isConfigurable(), 'isSuper' => $product->isSuper(), 'isSalable' => $product->isSalable(), 'isAvailable' => $product->isAvailable(), 'isVirtual' => $product->isVirtual(), 'isRecurring' => $product->isRecurring(), 'isInStock' => $product->isInStock(), 'weight' => $product->getSku()));
         // Add product images
         if (self::validateProductImage($product->getImage())) {
             $data['images']['full'] = array("url" => $product->getImageUrl());
         }
         if (self::validateProductImage($product->getSmallImage())) {
             $data['images']['smallImage'] = array("url" => $product->getSmallImageUrl($width = 88, $height = 77));
         }
         if (self::validateProductImage($product->getThumbnail())) {
             $data['images']['thumb'] = array("url" => $product->getThumbnailUrl($width = 75, $height = 75));
         }
         return $data;
         return $data;
     } catch (Exception $e) {
         Mage::logException($e);
     }
 }
Ejemplo n.º 22
0
 /**
  * Returns the longest category path ID for a product.
  *
  * @param Mage_Catalog_Model_Product $product
  * @param array $exclude_cats
  * @return array
  */
 public function getCategoryPathIds(Mage_Catalog_Model_Product $product, array $exclude_cats)
 {
     $categories = $product->getCategoryIds();
     $path = array();
     foreach ($categories as $category_id) {
         if (!isset($this->category_paths[$category_id])) {
             $category = Mage::getModel('catalog/category')->load($category_id);
             $this->category_paths[$category_id] = explode("/", $category->getPath());
         }
         // Only include categories with paths longer than the default
         // category and with a top-level parent not in the excluded list.
         if (count($this->category_paths[$category_id]) >= 3 && !in_array($this->category_paths[$category_id][2], $exclude_cats)) {
             $current_path = $this->category_paths[$category_id];
             if (sizeof($current_path) > sizeof($path)) {
                 $path = $current_path;
             }
         }
     }
     return $path;
 }
Ejemplo n.º 23
0
 /**
  * Get product breadcrumbs
  *
  * @param Mage_Catalog_Model_Product $product
  * @return array
  */
 public function getProductBreadcrumbs(Mage_Catalog_Model_Product $product)
 {
     $allPaths = array();
     $priorPaths = array();
     $defaultCategory = Mage::helper('crumbs')->getDefaultCategory();
     foreach ($product->getCategoryIds() as $catId) {
         $category = $this->getCategoryModel($catId);
         if (!Mage::helper('catalog/category')->canShow($category)) {
             continue;
         }
         if ($defaultCategory && in_array($defaultCategory, $category->getPathIds())) {
             $priorPaths[] = $category->getPathInStore();
         } else {
             $allPaths[] = $category->getPathInStore();
         }
     }
     if (count($priorPaths)) {
         $allPaths = $priorPaths;
     }
     $allPaths = $this->_removeDuplicates($allPaths);
     return $this->preparePaths($allPaths);
 }
 /**
  * @param Mage_Catalog_Model_Product $product
  * @return array
  */
 protected function _getProductCategoryNames(Mage_Catalog_Model_Product $product)
 {
     $names = array();
     $categoryIds = $product->getCategoryIds();
     foreach ($categoryIds as $categoryId) {
         $category = Mage::getModel('catalog/category')->load($categoryId);
         $filter = Mage::getModel('elasticsearch/text_filter', $category->getName());
         $filteredName = explode('-', $filter->filter());
         foreach ($filteredName as $namePart) {
             $names[] = $namePart;
         }
     }
     return $names;
 }
Ejemplo n.º 25
0
 /**
  * Refresh Product Enabled Index
  *
  * @param Mage_Catalog_Model_Product $product
  * @return Mage_Catalog_Model_Resource_Product
  */
 public function refreshIndex($product)
 {
     $writeAdapter = $this->_getWriteAdapter();
     /**
      * Ids of all categories where product is assigned (not related with store)
      */
     $categoryIds = $product->getCategoryIds();
     /**
      * Clear previous index data related with product
      */
     $condition = array('product_id = ?' => (int) $product->getId());
     $writeAdapter->delete($this->getTable('catalog/category_product_index'), $condition);
     /** @var $categoryObject Mage_Catalog_Model_Resource_Category */
     $categoryObject = Mage::getResourceSingleton('catalog/category');
     if (!empty($categoryIds)) {
         $categoriesSelect = $writeAdapter->select()->from($this->getTable('catalog/category'))->where('entity_id IN (?)', $categoryIds);
         $categoriesInfo = $writeAdapter->fetchAll($categoriesSelect);
         $indexCategoryIds = array();
         foreach ($categoriesInfo as $categoryInfo) {
             $ids = explode('/', $categoryInfo['path']);
             $ids[] = $categoryInfo['entity_id'];
             $indexCategoryIds = array_merge($indexCategoryIds, $ids);
         }
         $indexCategoryIds = array_unique($indexCategoryIds);
         $indexProductIds = array($product->getId());
         $categoryObject->refreshProductIndex($indexCategoryIds, $indexProductIds);
     } else {
         $websites = $product->getWebsiteIds();
         if ($websites) {
             $storeIds = array();
             foreach ($websites as $websiteId) {
                 $website = Mage::app()->getWebsite($websiteId);
                 $storeIds = array_merge($storeIds, $website->getStoreIds());
             }
             $categoryObject->refreshProductIndex(array(), array($product->getId()), $storeIds);
         }
     }
     /**
      * Refresh enabled products index (visibility state)
      */
     $this->refreshEnabledIndex(null, $product);
     return $this;
 }
Ejemplo n.º 26
0
 /**
  * Add URLs to the queue by product model
  *
  * @param Mage_Catalog_Model_Product $product
  * @return int
  */
 public function addProductToCrawlerQueue($product)
 {
     $productUrls = array();
     $origStore = Mage::app()->getStore();
     foreach (Mage::app()->getStores() as $storeId => $store) {
         Mage::app()->setCurrentStore($store);
         $baseUrl = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
         $productUrls[] = $product->getProductUrl();
         foreach ($product->getCategoryIds() as $catId) {
             $cat = Mage::getModel('catalog/category')->load($catId);
             $productUrls[] = rtrim($baseUrl, '/') . '/' . ltrim($product->getUrlModel()->getUrlPath($product, $cat), '/');
         }
     }
     Mage::app()->setCurrentStore($origStore);
     return $this->addUrlsToCrawlerQueue($productUrls);
 }
Ejemplo n.º 27
0
 /**
  * Set category ids to product data
  *
  * @param Mage_Catalog_Model_Product $object
  * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract
  */
 public function afterLoad($object)
 {
     $object->setData($this->getAttribute()->getAttributeCode(), $object->getCategoryIds());
     return parent::afterLoad($object);
 }
 /**
  * Get event for product
  *
  * @param Mage_Catalog_Model_Product $product
  * @return Enterprise_CatalogEvent_Model_Event
  */
 protected function _getProductEvent($product)
 {
     if (!$product instanceof Mage_Catalog_Model_Product) {
         return false;
     }
     $categoryIds = $product->getCategoryIds();
     $event = false;
     $noOpenEvent = false;
     $eventCount = 0;
     foreach ($categoryIds as $categoryId) {
         $categoryEvent = $this->_getEventInStore($categoryId);
         if ($categoryEvent === false) {
             continue;
         } elseif ($categoryEvent === null) {
             // If product assigned to category without event
             return null;
         } elseif ($categoryEvent->getStatus() == Enterprise_CatalogEvent_Model_Event::STATUS_OPEN) {
             $event = $categoryEvent;
         } else {
             $noOpenEvent = $categoryEvent;
         }
         $eventCount++;
     }
     if ($eventCount > 1) {
         $product->setEventNoTicker(true);
     }
     return $event ? $event : $noOpenEvent;
 }
Ejemplo n.º 29
0
 /**
  * Get the categories of the current product
  *
  * @param  Mage_Catalog_Model_Product $product Product
  * @return array Categories
  */
 protected function _getCategoryKeywords($product)
 {
     $categories = $product->getCategoryIds();
     $categoryArr = $this->_fetchCategoryNames($categories);
     $keywords = $this->_buildKeywords($categoryArr);
     return $keywords;
 }
Ejemplo n.º 30
0
 public function filterByAtts(Mage_Catalog_Model_Product $currentProduct, $atts, $ids = null)
 {
     $this->_joinedAttributes = array();
     $collection = $this->_collection;
     $rule = new AW_Autorelated_Model_Blocks_Rule();
     foreach ($atts as $at) {
         /*
          *  collect category ids related to product
          *  If category is anchor we should implode all of its subcategories as value
          *  If it's not we should get only its id
          *  If there is no category in product, get all categories product is in
          */
         if ($at['att'] == 'category_ids') {
             $category = $currentProduct->getCategory();
             if ($category instanceof Varien_Object) {
                 if ($category->getIsAnchor()) {
                     $value = $category->getAllChildren();
                 } else {
                     $value = $category->getId();
                 }
             } else {
                 $value = implode(',', $currentProduct->getCategoryIds());
                 $value = !empty($value) ? $value : null;
             }
         } else {
             $value = $currentProduct->getData($at['att']);
         }
         if (!$value) {
             $collection = NULL;
             return false;
         }
         $sql = $rule->prepareSqlForAtt($at['att'], $this->_joinedAttributes, $collection, $at['condition'], $value);
         if ($sql) {
             $collection->getSelect()->where($sql);
         }
     }
     if ($ids) {
         $collection->getSelect()->where('e.entity_id IN(' . implode(',', $ids) . ')');
     }
     $collection->getSelect()->group('e.entity_id');
     return $collection->getAllIds();
 }