Magento:通过集合加载产品与产品模型之间的区别

发布于 2024-09-26 05:25:57 字数 643 浏览 3 评论 0原文

因此,我们尝试通过具有特定标准的集合加载产品,我们没有 sku 或 id,因此当我们执行以下

 $prodModel->getCollection()
        ->addAttributeToFilter('visibility', $visibility)
        ->addAttributeToSelect('*')
        ->addCategoryFilter($cat)
        ->addAttributeToFilter('attribute_1', $sattribute_1)
        ->addAttributeToFilter('attribute_2', $attribute_2)
        ->addAttributeToFilter('type_id', 'configurable')
        ->load()
        ->getFirstItem()

操作时,我们得到了我们想要的产品,但由于某种原因它没有全部即使我们为所有属性指定了“*”。具体来说,我们没有得到的是媒体库属性。我们最终做的是 getFirstItem()->getId() 然后加载产品并且它可以找到。

我只是不明白为什么使用目录产品模型加载产品会有更多属性。

So we were trying to load a product through a collection with certain criteria, we didn't have the sku or the id so when we did the following

 $prodModel->getCollection()
        ->addAttributeToFilter('visibility', $visibility)
        ->addAttributeToSelect('*')
        ->addCategoryFilter($cat)
        ->addAttributeToFilter('attribute_1', $sattribute_1)
        ->addAttributeToFilter('attribute_2', $attribute_2)
        ->addAttributeToFilter('type_id', 'configurable')
        ->load()
        ->getFirstItem()

When doing this we got the product we wanted but for some reason it didn't have all of the attributes, even though we specified "*" for all attributes. Specifically the one we were not getting was the media gallery attribute. What we ended up doing is saying getFirstItem()->getId() then loaded the product and it worked find.

I just don't understand whey loading the product with the catalog product model would have more attributes.

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

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

发布评论

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

评论(1

请别遗忘我 2024-10-03 05:25:57

我知道您实际上询问了如何获取所有属性,但我注意到您还特别提到了媒体库属性。
恰好有一个获取产品图片最终 URL 的快捷方式。

(string)Mage::helper('catalog/image')->init($product, 'media_gallery');

转换为字符串调用 __toString 来执行巧妙的操作。您还可以在初始化后立即应用调整大小、旋转、水印等。

I understand you actually asked how to get all of the attributes but I notice you also mention the media gallery attribute specifically.
There happens to be a shortcut for getting the product image's final URL.

(string)Mage::helper('catalog/image')->init($product, 'media_gallery');

Casting to a string calls __toString which performs the cleverness. You can also apply resizing, rotation, watermarks, etc. immediately after initialising.

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