Skip to content

Instantly share code, notes, and snippets.

@vmasciotta
Created April 5, 2016 00:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmasciotta/d6e74499b4c191f77145b0e4a0a2c4c7 to your computer and use it in GitHub Desktop.
Save vmasciotta/d6e74499b4c191f77145b0e4a0a2c4c7 to your computer and use it in GitHub Desktop.
Magento2 Sandbox
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
//echo "hello world";
try {
require __DIR__ . '/app/bootstrap.php';
} catch (\Exception $e) {
echo $e->getMessage();
exit(1);
}
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$appState = $bootstrap->getObjectManager()->get('Magento\Framework\App\State');
$appState->setAreaCode('en');
//your code here
/** @var Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
$collection = $bootstrap->getObjectManager()->get('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory')->create();
$collection->addStoreFilter()
->addAttributeToSelect('*')
->addAttributeToFilter('price',['gt'=>30])
->setPageSize(10)
->load();
echo '<pre>';
foreach ($collection as $product) {
echo $product->getName() . ' ' . $product->getPrice() . '<br/>';
}
echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment