Guest User

Untitled

a guest
Oct 18th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. <?php
  2. /**
  3. * Get additional products from a brand in associated categories
  4. * @param $brand_id
  5. * @param $product_id
  6. * @param $category_ids
  7. * @return $collection
  8. */
  9. public function getMoreFromBrand($brand_id, $product_id, $category_ids=0, $platform='desktop') {
  10.  
  11. // Determine platform for product list limit
  12. if ($platform == 'desktop') $limit = Mage::getStoreConfig('brand/brand_extended_config/desktop_qty');
  13. elseif ($platform == 'mobile') $limit = Mage::getStoreConfig('brand/brand_extended_config/mobile_qty');
  14.  
  15. // Get product model, return products except $product_id
  16. $collection = Mage::getModel('brand/product')->getCollection()
  17. ->AddFieldToFilter('main_table.brand_id', $brand_id)
  18. ->AddFieldToFilter('main_table.product_id', array('nin' => $product_id));
  19.  
  20. // Join the category table
  21. $collection->join(array('category_product' => 'catalog/category_product'), 'main_table.product_id = category_product.product_id','category_product.category_id');
  22. $collection->getSelect()->join(array('product_status' => 'catalog_product_entity_int'), 'main_table.product_id = product_status.entity_id', array('product_status.value'));
  23. $collection->getSelect()->join(array('product_entity' => 'catalog_product_entity'), 'product_entity.entity_id = product_status.entity_id', array('product_status.value'));
  24. $collection->AddFieldToFilter('product_status.attribute_id', array('eq' => array('96')));
  25. $collection->AddFieldToFilter('product_status.value', array('eq' => array('1')));
  26.  
  27. // A product will contain an array of categories it lives in, use that array to get associated products by the brand
  28. if (count($category_ids) > 0) $collection->AddFieldToFilter('category_product.category_id', array('in' => array($category_ids)));
  29.  
  30. $collection->getSelect()->group('main_table.product_id');
  31. $collection->getSelect()->order('RAND()');
  32. $collection->getSelect()->limit($limit);
  33.  
  34. echo '<pre>';
  35. echo $collection->getSelect();
  36. print_r($collection->getData());
  37. exit;
  38.  
  39. //die($collection->getSelect());
  40. return $collection;
  41. }
Add Comment
Please, Sign In to add comment