Magento:通过集合加载产品与产品模型之间的区别
因此,我们尝试通过具有特定标准的集合加载产品,我们没有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道您实际上询问了如何获取所有属性,但我注意到您还特别提到了媒体库属性。
恰好有一个获取产品图片最终 URL 的快捷方式。
转换为字符串调用 __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.
Casting to a string calls
__toString
which performs the cleverness. You can also apply resizing, rotation, watermarks, etc. immediately after initialising.