Getting Value of product attribute on cart page even not assigned to that particular product Magento 2
Becuase you use same object every time in foreach. YOu need to create new object in foreach loop. So you final code look like this:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart');
$itemsCollection = $cart->getQuote()->getItemsCollection();
$itemsVisible = $cart->getQuote()->getAllVisibleItems();
$items = $cart->getQuote()->getAllItems();
foreach($itemsVisible as $item){
if($option = $item->getOptionByCode('simple_product')) {
$productId = $option->getProduct()->getId();
$product_object = $objectManager->create('Magento\Catalog\Model\Product');
$item_s = $product_object->load($productId);
echo $screen_size = $productId."/".$item_s->getScreenFrameSize()."/".$item_s->getFiberglassScreenRollSize()."/".$item_s->getScreenCornerSize()."<br>";
}
}
NOTE: Don't use object manager directly in code. Use product factory becuase factory will create new object every time.
Please Try something like this
....
function productData($pro_id)
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product_object = $objectManager->create('Magento\Catalog\Model\Product');
$item_s = $product_object->load($pro_id);
return $item_s;
}
....
$item_s = productData($productId); //In foreach loop