我正在代码中创建一个可配置的产品(我正在做一个导入模块),一切看起来都很好.添加属性,简单的库存项目添加到可配置产品,没有任何问题,但是,当我在字体末端查看项目时,它显示为一个简单的产品(没有选项),但当我保存打开并保存产品时管理面板然后正确显示前端的选项.
我在重新保存项目之前和之后使用以下代码来检查是否有任何属性不匹配(假设我遗漏了一些东西)
foreach ($product->getTypeInstance(true)->getEditableAttributes($product) as $code=>$attribute)
{
$val = Mage::getResourceModel('catalog/product')->getAttributerawValue($product->getId(), $code, $storeId);
Mage::log($code . '=>' . $val);
}
新鲜的导入产品(不显示选项)和手动保存的产品(确实如此)之间的所有值都匹配.
这是我用来创建产品的代码(我省略了将属性/简单项添加到可配置产品的位,但如果需要,请告诉我):
$productData = array(
'name' => $name,
'websites' => array(1, 2),
'short_description' => $shortDescription,
'description' => $longDesc,
'status' => 1,
'weight' => $weight,
'tax_class_id' => 2, //0:None;2:Taxable Goods;4:Shipping
'categories' => $categoryIds,
'price' => $sellPrice,
);
if ($parentStockItem == null) // != null is child item, == false is simple item, == null is config item
{
$productData['has_options'] = 1;
$productData['required_options'] = 1;
$productData['msrp_enabled'] = 2; //added to test as this was missing in my comparison check
$productData['msrp_display_actual_price_type'] = 4; //added to test as this was missing in my comparison check
}
return $mc->create($type, $setId, $stockCode, $productData);
解决方法:
好的,我通过在保存项目之前和之后比较数据库快照之间的数据来设法找到问题.
之所以发生这种情况,是因为cataloginventory_stock_status中的stock_status标志.此值默认为0,但是当您保存产品时,它将其设置为1.您还需要确保设置其他库存清单选项,以便将以下内容添加到我的例程中修复了问题:
$stockItem = Mage::getModel('cataloginventory/stock_item');
$stockItem->assignProduct($product);
$stockItem->setData('stock_id', 1);
$stockItem->setData('qty', 0);
$stockItem->setData('use_config_min_qty', 1);
$stockItem->setData('use_config_backorders', 1);
$stockItem->setData('min_sale_qty', 1);
$stockItem->setData('use_config_min_sale_qty', 1);
$stockItem->setData('use_config_max_sale_qty', 1);
$stockItem->setData('is_in_stock', 1);
$stockItem->setData('use_config_notify_stock_qty', 1);
$stockItem->setData('manage_stock', 1);
$stockItem->save();
//This section is what was required.
$stockStatus = Mage::getModel('cataloginventory/stock_status');
$stockStatus->assignProduct($product);
$stockStatus->saveProductStatus($product->getId(), 1);
现在,该项目在导入后正确显示选项.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。