create test file in root directory and place the below code excute it with domain/test.php
<?php
//THis is test
echo '<pre>';
error_reporting(0);
ini_set('display_errors', 1);
use Magento\Framework\App\Bootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$url = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $url->get('\Magento\Store\Model\StoreManagerInterface');
$websiteId = $storeManager->getWebsite()->getWebsiteId();
$state = $objectManager->get('\Magento\Framework\App\State');
$state->setAreaCode('frontend');
//$product = $objectManager->get('\Magento\Catalog\Model\Product')->load('2331');
$productCollection = $objectManager- >create('Magento\Catalog\Model\ResourceModel\Product\Collection');
/** Apply filters here */
$collection = $productCollection->addAttributeToSelect('*')
->load();
foreach ($collection as $product) {
//echo 'Name = '.$product->getName().'<br>';
$customOptions = $objectManager->get('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($product);
//print_r($customOptions->getData());
foreach ($customOptions as $option) {
$values = $option->getValues();
//print_r($option->getTitle());
if (empty($values)) {
echo $product->getName() . "===" . $product->getSku() . "===" . $option->getOptionId() . "===" . $option->getDefaultTitle() . "===" . "no options" . "<br />";
;
} else {
foreach ($values as $value) {
//print_r($value->getTitle());
echo $product->getName() . "===" . $product->getSku() . "===" . $option->getOptionId() . "===" . $option->getDefaultTitle() . "===" . $value->getTitle() . "===" . $value->getPrice() . "<br />";
}
}
}
//die("here");
}
?>
<?php
//THis is test
echo '<pre>';
error_reporting(0);
ini_set('display_errors', 1);
use Magento\Framework\App\Bootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$url = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $url->get('\Magento\Store\Model\StoreManagerInterface');
$websiteId = $storeManager->getWebsite()->getWebsiteId();
$state = $objectManager->get('\Magento\Framework\App\State');
$state->setAreaCode('frontend');
//$product = $objectManager->get('\Magento\Catalog\Model\Product')->load('2331');
$productCollection = $objectManager- >create('Magento\Catalog\Model\ResourceModel\Product\Collection');
/** Apply filters here */
$collection = $productCollection->addAttributeToSelect('*')
->load();
foreach ($collection as $product) {
//echo 'Name = '.$product->getName().'<br>';
$customOptions = $objectManager->get('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($product);
//print_r($customOptions->getData());
foreach ($customOptions as $option) {
$values = $option->getValues();
//print_r($option->getTitle());
if (empty($values)) {
echo $product->getName() . "===" . $product->getSku() . "===" . $option->getOptionId() . "===" . $option->getDefaultTitle() . "===" . "no options" . "<br />";
;
} else {
foreach ($values as $value) {
//print_r($value->getTitle());
echo $product->getName() . "===" . $product->getSku() . "===" . $option->getOptionId() . "===" . $option->getDefaultTitle() . "===" . $value->getTitle() . "===" . $value->getPrice() . "<br />";
}
}
}
//die("here");
}
?>
Comments
Post a Comment