Question

I have added a new column (PIN_ID) to the existing magento 2 table('sales_order') by 'Setup/UpgradeSchema', what's the best practice to access(get or retrieve) the data?

PS

Was it helpful?

Solution

Using ObjectManager you can access your custom field of table,

            $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
            $order = $objectManager->get('Magento\Sales\Model\Order');
            $order_information = $order->loadByIncrementId($order_id);
            $orderItems = $order_information->getAllItems();

            foreach ($orderItems as $item) {
                  $itemSku = $item->getPinId();
            }
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top