I am trying to get attribute option values for specific products.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$baseUrl = $objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore(0)->getBaseUrl();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$product1 = $objectManager->get('Magento\Framework\Registry')->registry('current_product');//get current product
$op_array = array();
$val_array = array();
$_product = $objectManager->create('Magento\Catalog\Model\Product')->load($product1->getId());
$_childProducts = $_product->getTypeInstance()->getUsedProducts($_product);
foreach ($_childProducts as $simpleProduct){
// echo '<pre>' , var_dump($simpleProduct->getData()) , '</pre>';
$sku = $simpleProduct->getSku();
// echo "<br/>";
$stringSku = '"' . $sku . '"';
$sql = "select * from inventory_stock_4 where sku =". $stringSku;
$result = $connection->fetchAll($sql);
//var_dump($result);
//echo $option_label = $result[0]['quantity'];
//echo "<br/>";
$tableName = $resource->getTableName('eav_attribute_option_value');
$sql2 = "select distinct * FROM " . $tableName . " where option_id=".$simpleProduct['jasani_size'];
$result2 = $connection->fetchAll($sql2);
$option_label = $result2[0]['value'];
foreach($result2 as $size){
var_dump($size);
}
I get an array like this
array(4) { ["value_id"]=> string(3) "611"
["option_id"]=> string(2) "25" ["store_id"]=> string(1) "1"
["value"]=> string(2) "XS" }
array(4) { ["value_id"]=> string(3) "612"
["option_id"]=> string(2) "25" ["store_id"]=> string(1) "0"
["value"]=> string(2) "XS" }
array(4) { ["value_id"]=> string(3) "613"
["option_id"]=> string(2) "25" ["store_id"]=> string(1) "3"
["value"]=> string(2) "XS" }
array(4) { ["value_id"]=> string(3) "614"
["option_id"]=> string(2) "25" ["store_id"]=> string(1) "4"
["value"]=> string(2) "XS" }
array(4) { ["value_id"]=> string(3) "619"
["option_id"]=> string(2) "27" ["store_id"]=> string(1) "1"
["value"]=> string(1) "M" }
array(4) { ["value_id"]=> string(3) "620"
["option_id"]=> string(2) "27" ["store_id"]=> string(1) "0"
["value"]=> string(1) "M" }
array(4) { ["value_id"]=> string(3) "621"
["option_id"]=> string(2) "27" ["store_id"]=> string(1) "3"
["value"]=> string(1) "M" }
array(4) { ["value_id"]=> string(3) "622"
["option_id"]=> string(2) "27" ["store_id"]=> string(1) "4"
["value"]=> string(1) "M" }
I get this repeated values like XS and M I can't filter unique vales in this.
I also tried array_unique(), array_filter() nut no use.
$option_label = []before the first foreach and replace$option_label = $result2[0]['value'];with$option_label[$result2[0]['value']] = $result2[0]['value'];you will have an array of unique labels.