isSaleable() 和 isAvailable() 有什么区别?
我正在研究在我的 Magento 主题的(单独)产品页面上显示库存情况,但我对此并不完全理解。
我看到模板中使用了两种方法来检查产品是否可供销售:
Mage_Catalog_Model_Product::isAvailable()
Mage_Catalog_Model_Product::isSaleable()
我自己的发现:
我看到 isSalable()
(又由 isSaleable()
调用)调用 isAvailable()
但也调度两个事件 (>catalog_product_is_salable_before
和catalog_product_is_salable_after
)。
在前端,我注意到在 Magento 的基本模板中 isAvailable()
用于决定是否将产品显示为“有货”或“缺货”; isSaleable()
用于决定是否显示“添加到购物车”按钮等。
在后端,我注意到,当库存数量变为零并且不允许延期交货时,产品的库存可用性将变为“缺货”。 当库存数量变为零并且允许延期交货时,产品的库存量保持不变。
问题:
“库存可用性”和“库存数量”属性显然彼此之间以及所提到的 PHP 方法之间存在联系。我想知道:
PHP 方法
isAvailable()
和 PHP 方法之间的语义区别是什么isSaleable()
是以及为什么我会使用其中一个而不是另一个;它是什么,我似乎还不知道它们与这些属性和 Magento 行为的关系。
谢谢。
编辑:
我已经尝试了产品的库存数量(-1,0,1)、库存可用性(进/出)和延期交货(开/关)的所有相关组合,这就是结果:
St.Qu BckOrd St.Av isSalable() isSaleable() isAvailable() -1 0 0 0 0 0 -1 0 1 N/A N/A N/A -1 1 0 0 0 0 -1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 N/A N/A N/A 0 1 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 1 0 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1
只是为了完整性:
St.Av 0 = out of stock
St.Av 1 = in stock
BckOrd 0 = no backorders allowed
BckOrd 1 = backorders are allowed
Magento 中的库存可用性开关控制着所有 PHP 方法的返回值,但是当缺货关闭并且库存数量低于 1 时,库存可用性将自动重置为“缺货”(因此N/A
行)。
I'm working on the display of the stock availability on the (individual) product page of my Magento theme, and there's something I don't completely understand about this.
I see two methods being used in the templates to check whether a product is available for sale:
Mage_Catalog_Model_Product::isAvailable()
Mage_Catalog_Model_Product::isSaleable()
My own findings:
I see that isSalable()
(which in turn is called by isSaleable()
) calls isAvailable()
but also dispatches two events (catalog_product_is_salable_before
and catalog_product_is_salable_after
).
On the frontend, I've noticed that in Magento's base template isAvailable()
is used to decide whether to display the product as "in stock" or "out of stock"; isSaleable()
is used to decide something like whether to show an "Add to Cart" button.
On the backend, I've noticed that when the stock quantity becomes zero and backorders are not allowed, the stock availability of a product goes to "out of stock".
When the stock quantity becomes zero and backorders are allowed, the stock availability of the product remains unchanged.
Question:
The properties "stock availability" and "stock quantity" are obviously linked with each other and the mentioned PHP methods. I would like to know:
what the semantic difference between the PHP methods
isAvailable()
andisSaleable()
is and why I would use one over the other;what it is I appear not yet to know about their relation with these properties and Magento's behavior.
Thank you.
EDIT:
I've tried every relevant combination of stock quantity (-1,0,1), stock availability (in/out of), and backorders (on/off) for a product and this is the result:
St.Qu BckOrd St.Av isSalable() isSaleable() isAvailable() -1 0 0 0 0 0 -1 0 1 N/A N/A N/A -1 1 0 0 0 0 -1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 N/A N/A N/A 0 1 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 1 0 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1
Just for the sake of completeness:
St.Av 0 = out of stock
St.Av 1 = in stock
BckOrd 0 = no backorders allowed
BckOrd 1 = backorders are allowed
It is the stock availability switch in Magento that controls the return value of all of the PHP methods, but when backorders are off and stock quantity drops below 1, the stock availability will automatically be reset to 'out of stock' (hence the N/A
rows).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果我没记错的话,这些检查的差异与已下订单的产品预订有关。当客户将产品添加到订单中时,这些产品仍然在您的库存中,因此它们仍然可用。不过,它们无法销售,因为它们已经被另一位客户订购了。
因此,语义差异是:
您可以尝试通过订购产品来验证这一点。并进行与您已经做过的相同的检查。这应该会导致可用产品数量和可销售产品数量之间的差异。
编辑:
更多信息请参见:
https://blog.magestore.com/magento -多源库存-msi/#a3
If I'm not mistaken, the difference in these checks has to do with reservations of products for placed orders. When a customer adds products to an order, these products will still be in your stock, so they are still available. Though, they aren't saleable, because they have already been ordered by another customer.
So the semantic difference is:
You could try to validate this by placing an order for a product. And doing the same check as you already did. This should cause a difference between the amount of available products and the amount of saleable products.
Edit:
More info here:
https://blog.magestore.com/magento-multi-source-inventory-msi/#a3
isSeable()
看起来像是在检查是否达到 0isAvailable()
看起来像是在计数isSeable()
looks like it's checking if it reaches 0isAvailable()
looks like it's counting我发现它们存在语义差异。如果该商品设置为允许缺货,则没有库存的商品仍然可以销售。据我所知,看起来
isAvailable
检查产品类型实例以查看是否如果确实有货,该产品类型可能可以出售。因此,大胆猜测一下您何时会选择其中一个:
如果您正在检查单个产品以查看该产品是否确实可供销售,您应该使用
isSalable()
,因为它将调用isAvailable()
。要检查产品(您不知道其类型)是否可以出售,并且我想跳过检查产品类型的步骤,您可以在产品上调用
isAvailable()
。isAvailable()
检查产品类型是否可销售。isSalable()
检查产品是否可销售。isSalable()
是isSalable()
的别名。I see those having semantic differences. An item that is not in stock can still be saleable if said item is set to allow backorders.As far as I can tell, it looks like
isAvailable
checks a product type instance to see if the product type could be for sale if it is indeed available.So, to venture a guess at when you might choose one over the other:
If you are checking an individual product to see if said product is actually ready for sale, you should use
isSalable()
, as it will callisAvailable()
.To check if a product (whose type you don't know off hand) could be sold, and I suppose skipping the step of checking the product's type, you could call
isAvailable()
on the product.isAvailable()
checks if a product's type is salable.isSalable()
checks if a product is salable.isSaleable()
is an alias ofisSalable()
.就我而言,
isSaleable()
意味着您正在检查准备出售的最热门产品。而isAvailable()
表示您正在从可用列表中检查产品。As far as my concern,
isSaleable()
means you are checking the top most product that is ready for sale. WhileisAvailable()
means you are checking the product from the lists that are available.isAvailable() 用于决定是将产品显示为有货还是缺货,而isSaleable() strong> 用于决定是否显示添加到购物车按钮。
isAvailable() is used to decide whether to display the product as in stock or out of stock, while isSaleable() is used to decide whether to show an Add to cart button or not.