那么这里的笔记帮我搞定了.所以我想我会与您分享将简单产品添加到现有可配置产品的代码.
这段代码假设简单的产品是一个有效的产品,我不确定如果不是这样会发生什么.
private function _attachProductToConfigurable( $_childProduct, $_configurableProduct ) {
$loader = Mage::getResourceModel( 'catalog/product_type_configurable' )->load( $_configurableProduct );
$ids = $_configurableProduct->getTypeInstance()->getUsedProductIds();
$newids = array();
foreach ( $ids as $id ) {
$newids[$id] = 1;
}
$newids[$_childProduct->getId()] = 1;
$loader->saveProducts( $_configurableProduct->getId(), array_keys( $newids ) );
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
18609 次 |
最近记录: |