| Current Path : /home/rtorresani/www/ |
| Current File : //home/rtorresani/www/test.php |
<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$storeId = 4;
$idCategory = 226;
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
//$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$state = $objectManager->get(Magento\Framework\App\State::class);
$state->setAreaCode('frontend');
$storeManager = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class);
$storeManager->setCurrentStore($storeId);
$categoryFactory = $objectManager->get('\Magento\Catalog\Model\CategoryFactory');
// $store = $objectManager->create(\Magento\Store\Model\Store::class)->load($storeId);
// $category = $categoryFactory->create()->setStore($store)->load($idCategory);
$category = $categoryFactory->create()->load($idCategory);
$categoryProducts = $category->getProductCollection()->addAttributeToSelect('*');
$categoryProducts->addAttributeToFilter('type_id', ['in' => ['simple', 'configurable']]);
// echo $categoryProducts->getSelect()->__toString();
$idProducts = '';
foreach ($categoryProducts as $product) {
$idProducts .= $product->getId(). ',';
}
$idProducts = substr($idProducts, 0, -1);
echo $idProducts;
echo "\n\n";