Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Get additional products from a brand in associated categories
- * @param $brand_id
- * @param $product_id
- * @param $category_ids
- * @return $collection
- */
- public function getMoreFromBrand($brand_id, $product_id, $category_ids=0, $platform='desktop') {
- // Determine platform for product list limit
- if ($platform == 'desktop') $limit = Mage::getStoreConfig('brand/brand_extended_config/desktop_qty');
- elseif ($platform == 'mobile') $limit = Mage::getStoreConfig('brand/brand_extended_config/mobile_qty');
- // Get product model, return products except $product_id
- $collection = Mage::getModel('brand/product')->getCollection()
- ->AddFieldToFilter('main_table.brand_id', $brand_id)
- ->AddFieldToFilter('main_table.product_id', array('nin' => $product_id));
- // Join the category table
- $collection->join(array('category_product' => 'catalog/category_product'), 'main_table.product_id = category_product.product_id','category_product.category_id');
- $collection->getSelect()->join(array('product_status' => 'catalog_product_entity_int'), 'main_table.product_id = product_status.entity_id', array('product_status.value'));
- $collection->getSelect()->join(array('product_entity' => 'catalog_product_entity'), 'product_entity.entity_id = product_status.entity_id', array('product_status.value'));
- $collection->AddFieldToFilter('product_status.attribute_id', array('eq' => array('96')));
- $collection->AddFieldToFilter('product_status.value', array('eq' => array('1')));
- // A product will contain an array of categories it lives in, use that array to get associated products by the brand
- if (count($category_ids) > 0) $collection->AddFieldToFilter('category_product.category_id', array('in' => array($category_ids)));
- $collection->getSelect()->group('main_table.product_id');
- $collection->getSelect()->order('RAND()');
- $collection->getSelect()->limit($limit);
- echo '<pre>';
- echo $collection->getSelect();
- print_r($collection->getData());
- exit;
- //die($collection->getSelect());
- return $collection;
- }
Add Comment
Please, Sign In to add comment