magento 2 ignoring completly ignoring addAttributeToSort
Clash Royale CLAN TAG#URR8PPP
magento 2 ignoring completly ignoring addAttributeToSort
This code is working perfectly in MAMP but the moment I move it to Linux it ignore the $category_product->addAttributeToSort('position', 'asc');
It just gives me the array in the default order instead of by position.
$Cats = explode('/',$_SERVER['REQUEST_URI']);
if($Cats[9] == '' && is_numeric($Cats[8]))
$Cats[9] = $Cats[8];
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_product = $objectManager->get('MagentoFrameworkRegistry')->registry('current_product');
$productId = $block->getProduct()->getId();
$cat_ids = $block->getProduct()->getCategoryIds();
$product = $objectManager->create('MagentoCatalogModelProduct');
$category = $objectManager->create('MagentoCatalogModelCategory')->load($Cats[9]);
$category_product = $category->getProductCollection();
$category_product->addAttributeToSort('position', 'asc');
$cat_prod_ids = $category_product->getAllIds();
$_pos = array_search($productId, $cat_prod_ids); // get position of current product
$_next_pos = $_pos+1;
$_prev_pos = $_pos-1;
$keys = array_keys($cat_prod_ids);
echo '<pre>';
print_r($cat_prod_ids);
echo '</pre>';
Where am I going wrong with this? I'm racking my brain.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.