0

嗨,我使用以下代码获得了产品的最大元素,但它没有显示size attribute我的产品,尺寸属性在前端可见,但我不明白为什么它不使用此代码打印

<?php
ob_start();
session_start();
ini_set('display_errors', 1);
//for order update
include '../../../../app/Mage.php';
Mage::app('default');
echo '<pre>';
if(isset($_REQUEST['productid'])){
$productId = $_REQUEST['productid'];
}else{

$productId = '12402'; // product ID 10 is an actual product, and used here for a test
}
$product = Mage::getModel('catalog/product')->load($productId);  //load the product     
//$product_id = $product->getId();
//$created_at = $product->getcreated_at();
//$description = $product->getdescription();
//$short_description = $product->getshort_description();
//$sku = $product->getsku();
//$size_fit = $product->getsize_fit();
//$style_ideas = $product->getstyle_ideas();
//$name = $product->getname();
//$price = $product->getprice();
//$stocklevel = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();  
4

5 回答 5

3

如果它的 size_fit 属性(我猜是因为它是您代码中唯一的大小尝试..),请使用$product->getSizeFit(). 仅供大小使用$product->getSize()。如果这没有返回任何内容,请发布属性安装程序(如果有的话)。Mufadall 他的回答也是正确的,但判断你的代码你只是使用了错误的语法。

基本上根据魔术get方法,第一个字母在下划线之后变成大写字母和所有其他字母。

例如:获取my_sample_attribute使用getMySampleAttribute().

getData('my_sample_attribute')也是一种选择,但你不应该养成这样做的习惯,因为在某些情况下,对于某些属性getData('attribute')返回不同的值然后getAttribute()......

于 2013-01-10T13:04:01.247 回答
2
$product->getData($attribute_code);

将返回您的实际属性值。对于具有下拉类型的属性,它将返回选项 id

$product->getResource()->getAttribute($attribute_code)->getFrontend()->getValue($product);

将返回实际值

于 2013-01-10T07:12:32.167 回答
1

你可以使用这个:

$product->getData('Your Attribute ID');
于 2013-01-10T07:04:15.710 回答
0

转到尺寸属性并检查产品列表中使用的下拉菜单是否设置为否,然后将其设置为是,之后您可以使用其他产品属性获取您的尺寸属性

于 2013-01-10T07:07:06.820 回答
0

您可以使用 getter 或 getData(); getter 在 magento 中使用魔术 __get() 方法设置,您可以通过以下方式使用它:

$product->getDescription() // ( to get description attribute)
$product->getShortDescription() // (to get short_description attribute)

所以基本上你用下划线爆炸属性,并将单词大写,你会得到你需要放在“get”之后的东西。

这是我一直在使用的非常有用的东西

Zend_Debug::dump($product->getData());

这将为您提供您必须使用的所有数据。如果您缺少数据,则意味着它没有加载。

祝你好运!

于 2013-01-10T12:08:36.287 回答