php 即使禁用了配置产品,Magento 也能从简单产品中获取可配置产品
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9174653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Magento get configurable product from simple product even if config product is disabled
提问by gregdev
I need to get the parent configurable product from a simple product, even if the parent product is marked as disabled. I also need to get the status of the configurable product (enabled or disabled).
我需要从一个简单的产品中获取父可配置产品,即使父产品被标记为禁用。我还需要获取可配置产品的状态(启用或禁用)。
Right now I'm getting the parent product like this:
现在我得到这样的父产品:
$parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
if (isset($parentIds[0])) {
$product = Mage::getModel('catalog/product')->load($parentIds[0]);
}
This works perfectly unless the configurable product has been disabled, where the $parentIds array is empty. I need to get the configurable product even if it's disabled, and also determine if the configurable product is enabled/disabled.
除非禁用可配置产品,否则 $parentIds 数组为空,否则这非常有效。即使已禁用,我也需要获取可配置产品,并确定可配置产品是否已启用/禁用。
Any help would be appreciated!
任何帮助,将不胜感激!
回答by Neil Aitken
I've done a little digging around, and I can't seem to reproduce your issue.
我已经做了一些挖掘,我似乎无法重现你的问题。
When I call getParentIdsByChild() on a simple with a disabled configurable, I still get the parent product ID.
当我调用 getParentIdsByChild() 一个简单的禁用可配置时,我仍然得到父产品 ID。
$parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')
->getParentIdsByChild(14412);
var_dump($parentIds);
Gives me:
给我:
array(1) {
[0]=>
string(5) "14446"
}
14446 has a status of disabled. I've also tried it as in stock and out of stock.
14446 的状态为禁用。我也试过有存货和缺货的情况。
Looking at the actual function on the resource file
查看资源文件上的实际功能
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable::getParentIdsByChild()
I can see that it looks in the table catalog_product_super_link
which doesn't have any fields for status, and therefore should always return the parent ID, if the product link exists.
我可以看到它在catalog_product_super_link
没有任何状态字段的表中查找,因此如果产品链接存在,则应始终返回父 ID。