在 magento 中从类别及其属性中提取产品

发布于 2024-09-14 14:47:42 字数 87 浏览 1 评论 0原文

我将使用什么类型的块以及我将调用什么方法。

另外,它会返回什么类型的数组,以及我在哪里可以找到属性、价格和所有这些好东西。

谢谢

what type of block would i use and what method would I call.

Also what type of array would it return and where would I find the attributes , price and all that good stuff.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲性难收 2024-09-21 14:47:42

在模块中声明您自己的块,并使用以下代码来获取您需要的产品:

function getProducts() {
    $id = $this->getCategoryId(); // you will have to call setCategoryId somewhere else
    $category = Mage::getModel("catalog/category")->load($id);

    $products = $category->getProductCollection();
    $products->addAttributeToSelect("*"); // adds all attributes
    //$products->addAttributeToSelect(array("name", "color")); // more precise way to add attributes

    return $products;
}

然后,在您看来:

$products = $this->getProducts(); // this is a collection object, not an array, but we can iterate over it anyway.
foreach($products as $productObject) {
    $color = $productObject->getColor();
    $name = $productObject->getName();
    $sku = $productObject->getSku(); // some things are retrieved even if you don't ask for them.
}

这应该可以帮助您开始。有关如何检索属性的更多信息,请查看 app/code/core/Mage/Catalog/Model/Product.php。如果您仍然遇到问题,请发布一些您尝试过的代码,我们可以继续。

希望有帮助!

谢谢,

Declare your own block in a module and use the following code to get the products you need:

function getProducts() {
    $id = $this->getCategoryId(); // you will have to call setCategoryId somewhere else
    $category = Mage::getModel("catalog/category")->load($id);

    $products = $category->getProductCollection();
    $products->addAttributeToSelect("*"); // adds all attributes
    //$products->addAttributeToSelect(array("name", "color")); // more precise way to add attributes

    return $products;
}

Then, in your view:

$products = $this->getProducts(); // this is a collection object, not an array, but we can iterate over it anyway.
foreach($products as $productObject) {
    $color = $productObject->getColor();
    $name = $productObject->getName();
    $sku = $productObject->getSku(); // some things are retrieved even if you don't ask for them.
}

That should get you started. Take a look at app/code/core/Mage/Catalog/Model/Product.php for more information on how to retrieve attributes. If you continue to have trouble, post some code you've tried and we can keep going.

Hope that helps!

Thanks,
Joe

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文