cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing Custom Attribute via PHP

Highlighted

Accessing Custom Attribute via PHP

Hello,

I want to access a certain attribute from an item. How do I achieve this?
The attribute is calles arzneimittel and can be any text.

 

$ist_arzneimittel =false;
$ist_mengenbeschraenkung = false;
$qty_ordered = 0;
$text_ist_arzneimittel="";
foreach ($shipment->getItems() as $item) {
    $qty_ordered = $item->getQtyOrdered();
    if (!$item->getParentItemId()) {            
            $text_ist_arzneimittel =  $item->getarzneimittel();
			
		}

        if ($text_ist_arzneimittel=="JA") {
            $ist_arzneimittel=true;
        }
		if ($text_ist_arzneimittel=="HOM") {
            $ist_arzneimittel=true;
        }     
		if ($ist_arzneimittel && $qty_ordered>3)
			$ist_mengenbeschraenkung = true;
			
        
    }

}
1 REPLY 1
Highlighted

Re: Accessing Custom Attribute via PHP

Hello @meineapo 

 

Please share in which phtml file or at which process you want to get get it ?

For a quick fix :

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load('YOUR PRODUCT ID');
echo $product->getArzneimittel();

This is not standard approach but it will work, or let us know where you want to get the product attribute.

 

Hope it helps ! 

Problem Solved ? Click on 'Kudos' & Accept as Solution to encourage to write more answers !