如何在 Magento 的简单产品中显示颜色和尺寸
How to display color and size in a simple product in Magento
我正在开发一个 Magento 商店,我需要在前端显示一个简单产品的颜色和尺寸,可以吗?
我只在可配置产品上得到了它,但在简单产品上却没有。
像这样:
http://www.saiajustamodafesta.com.br/loja/vestido-longo-saia-justa.html
有人可以帮助我吗?
谢谢。
在你的 view.phtml getColor(); ?> 替换为任何属性代码,这里重要的是属性必须在 catalog_product_flat 表中,为此,您的属性必须定义为 "use_in_product_listing"。你好。
在你的前端/[你的包]/[你的主题]/template/catalog/product/view.phtml 文件
$color = $_product->getColor();
<img src="<?php echo $this->getSkinUrl('images/'.$color.'.jpg'); ?>">
您需要上传与颜色名称 ex red.jpg 以及尺寸
相同的 jpg 图片
获取彩色图像属性
$color_code="color";
$colorValue = $objectManager->get('Magento\Catalog\Model\Product')->load($_product->getId())->getData($color_code);
$swatchHelper=$objectManager->get("Magento\Swatches\Helper\Data");
$swatchData = $swatchHelper->getSwatchesByOptionsId([$colorValue]);
<img class="object-fit-contain w-100 h-100" src="<?=
$objectManager->get('Magento\Store\Model\StoreManagerInterface')
->getStore()
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA).
'attribute/swatch'.$swatchData[$colorValue]['value']?>" alt="color"/>
对于 Magento 2,如果您有报价项或不包含颜色属性的产品对象:
$product = $_item->getProduct();
$product->getResource()->load($product, $product->getId(),['color']);
//then you can get attribute data
$value = $product->getColor(); //52
$label = $product->getResource()->getAttribute('color')->getFrontend()->getLabel(); // Color
$text = $product->getResource()->getAttribute('color')->getFrontend()->getValue($product); //Orange
我正在开发一个 Magento 商店,我需要在前端显示一个简单产品的颜色和尺寸,可以吗?
我只在可配置产品上得到了它,但在简单产品上却没有。
像这样: http://www.saiajustamodafesta.com.br/loja/vestido-longo-saia-justa.html
有人可以帮助我吗?
谢谢。
在你的 view.phtml getColor(); ?> 替换为任何属性代码,这里重要的是属性必须在 catalog_product_flat 表中,为此,您的属性必须定义为 "use_in_product_listing"。你好。
在你的前端/[你的包]/[你的主题]/template/catalog/product/view.phtml 文件
$color = $_product->getColor();
<img src="<?php echo $this->getSkinUrl('images/'.$color.'.jpg'); ?>">
您需要上传与颜色名称 ex red.jpg 以及尺寸
相同的 jpg 图片获取彩色图像属性
$color_code="color";
$colorValue = $objectManager->get('Magento\Catalog\Model\Product')->load($_product->getId())->getData($color_code);
$swatchHelper=$objectManager->get("Magento\Swatches\Helper\Data");
$swatchData = $swatchHelper->getSwatchesByOptionsId([$colorValue]);
<img class="object-fit-contain w-100 h-100" src="<?=
$objectManager->get('Magento\Store\Model\StoreManagerInterface')
->getStore()
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA).
'attribute/swatch'.$swatchData[$colorValue]['value']?>" alt="color"/>
对于 Magento 2,如果您有报价项或不包含颜色属性的产品对象:
$product = $_item->getProduct();
$product->getResource()->load($product, $product->getId(),['color']);
//then you can get attribute data
$value = $product->getColor(); //52
$label = $product->getResource()->getAttribute('color')->getFrontend()->getLabel(); // Color
$text = $product->getResource()->getAttribute('color')->getFrontend()->getValue($product); //Orange