magento custom attribute label disappears - magento

I've created a new phtml page to put inside the view page of the product, in this phtml page I called a new custom attribute that I have associated at the product, whit this code (I've the suggestion in this website, and this was working wonderfully!):
<?php $product_id = Mage::registry('current_product')->getId();
$_product=Mage::getModel('catalog/product')->load($product_id);
echo $_product->getAttributeText('video'); ?>
but now I have made the new magento update and my custom attribute is disappeared, this is strange because I don't work in the base file of Magento but I've created a my theme to work.
It's possible that something is changed in Magento?
Thank you for the help!

Try this way:
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct();
//Display custom attribute.
//Attribute code = video;
$product = Mage::getModel('catalog/product')->load($_product->getId());
$attribute = $product->getResource()
->getAttribute('video')
->getFrontend()->getValue($product);
echo $attribute;
From My blog

Related

Magento2.4: How to get Salable quantity in list.phtml file?

How can I get salable quantity on list.phtml or category page file, I want to show labels on products with 0 salable quantity.
Are there any other approaches without using object manager?
Please use this code in phtml file to get salable qty
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$StockState = $objectManager->get('\Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku');
$qty = $StockState->execute($_product->getSku());
echo($qty[0]['qty']);
Try the below code to get salable QTY.
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$StockState = $objectManager->get('\Magento\InventorySalesApi\Api\GetProductSalableQtyInterface');
$qty = $StockState->execute($_product->getSku(), 2);
?>
Either Object Manager is not a good approach, but you need to inject in your custom module such as:
namespace Cloudways\Module\ModelName;
use Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku;
Refer Link: https://magento.stackexchange.com/questions/301956/how-to-get-salable-qty-in-magento-2-3-3/302187#302187

Magento getAttribute not working with listing product

echo $_product->getResource()->getAttribute($attribute)->getFrontend()->getValue($_product);
This code is not working fine in view.phtml it is not return first attribute code value.
when i write this code on view page, it is not showing first product attribute and all after first in loop are showing fine.
This is my all code
<?php
$productAttributeTh = array('Color','Item','Size');
$configurableProduct = Mage::getModel('catalog/product')->load($_product->getId());
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$configurableProduct);
foreach($childProducts as $child) {
$product_id = $child->getId();
$obj = Mage::getModel('catalog/product');
$_childProduct = $obj->load($product_id); // Enter your Product Id in $product_id
foreach ($productAttributeTh as $key => $productAttributeValue){
$productAttribute = $_childProduct->getResource()->getAttribute($productAttributeValue)->getFrontend()->getValue($_childProduct);
echo $productAttribute;
}
} ?>
You need to make sure your attribute is set to be used in list. Go to;
Catalog > Attributes > Manage Attributes
Find your attribute, and open it. Scroll down to the option 'used in product listing' and set it 'yes'. Save and then reindex attributes.
Try this.
Mage::getResourceModel('catalog/product')->getAttributeRawValue($productId, 'attribute_code', $storeId);
Or
$attribute_value = $product->getResource()->getAttribute($attribute_code)->getFrontend()->getValue($product);
i hope this will help you.

Show Product's Custom Attributes to Homepage or static page

I want to echo the custom attributes to any other page, except Product Page or Category Listing
One way of getting custom attribute in nearly any page can be done as following (in PHP):
$product_id = $this->getProduct()->getId(); // note that this changes depending on how you load your product
$storeId = Mage::app()->getStore()->getStoreId();
$value = Mage::getResourceModel('catalog/product')->getAttributeRawValue($product_id, 'your_power_attribute_id', $storeId);
echo $value;

How to show the value of an attribute in shopping cart?

I added an attribute 'items' having input type textbox in admin.I want to show the value of that attribute in shopping cart.For that i have added this code in template/checkout/cart/sidebar-top.phtml which is below:
<?php
$productId = $_item->getId();
$productInfo = Mage::getModel("catalog/product")->load($productId);
echo $productInfo->getAttributeText('product_type');
?>
but when i am adding this above code showing
Fatal error: Call to a member function getId() on a non-object
if anyone knows this,please help me out.thanks!
Use the below code
$productId = $_item->getProduct()->getId();
$productInfo = Mage::getModel("catalog/product")->load($productId);
echo $productInfo->getAttributeText('product_type');
Are you talking about custom option or simple attribute?
For Simple attribute (text) and if you are on product page try belo code:
<?php $_item = $this->getItem()?>
<?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId()) ?>
<?php echo $_product->getResource()->getAttribute('attribute_code')->getFrontend()->getValue($_product); ?>
If you are not on the product page then you can use the below code, load the product by sku and get your attribute value
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku());
echo $product->getResource()->getAttribute('attribute_code')->getFrontEnd()->getValue($product);

Magento - How to get attributes of a child product of a bundled item

I need to retrieve a simple text attribute from a child product belonging to a bundled product if it exists. This needs to be done on the shopping cart page. The below is the code I've been messing around with to see what I can retrieve.
The file is template/checkout/cart/item/default.phtml in the theme folder.
$_item = $this->getItem();
$_product = $this->getProduct();
$_product = Mage::getModel('catalog/product')->load($_product->getId());
$isVisibleProduct = $_item->getProduct()->isVisibleInSiteVisibility();
$itemsCollection = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach($itemsCollection as $item) {
echo $item->getId();
$_bProduct = Mage::getModel('catalog/product')->load($item->getId());
echo '<pre>';
var_dump($_bProduct);
echo '</pre>';
echo '<br>';
echo $_bProduct->getData('backorder_shipment_date');
}
To access custom attributes on all pages, you should use :
getItemCollection()
or
getProductCollection()
also, check this link Accessing Custom Product Attributes in the Cart/Checkout Area

Resources