【问题标题】:Magento Associated Product OptionsMagento 相关产品选项
【发布时间】:2010-12-16 16:58:00
【问题描述】:

我已将我的所有产品导入为configurable,并将它们的选项导入为simple 产品类型,所有简单产品都具有正确的尺寸属性,可配置产品具有正确的attribute_set

将产品选项与其产品相关联的最佳方式是什么?

如果可以的话,我宁愿不使用 SQL 或手动执行此操作!

提前致谢

【问题讨论】:

    标签: php magento magento-1.4


    【解决方案1】:

    据我了解您的问题,您想将简单产品分配给其可配置的父级吗? 如果是这样,请查看 Mage_Catalog_Model_Product_Type_Configurable 模型。有方法 save() 调用资源模型的方法 saveProducts($mainProduct, $productIds):

    Mage::getResourceModel('catalog/product_type_configurable')
                ->saveProducts($this->getProduct($product), $productIds);
    

    【讨论】:

    • 能否请您稍微扩展一下该代码的放置位置,以便$this 正常工作?我想为每个可配置产品创建一个简单的 php 文件,其中包含我的简单产品 ID 数组
    • 如果是单独的 php 文件,首先你需要包含所有 magento 核心库并启动应用程序 Mage::app($mageRunCode, $mageRunType, $mageRunOptions),就像在 index.php 中一样 -使使用 Magento 核心成为可能。之后写类似: $configurableProducts = array('1' => array(1, 2, 3), 2=> array(4, 5, 6)); $model = Mage::getResourceModel('catalog/product_type_configurable'); foreach ($configurableProducts as $mainProductId => $childProductsId) {$model->saveProducts($mainProductId, $childProductsId);}
    【解决方案2】:

    我一直认为使用 SOAP-API 是不可能的(如 here 的解释)。

    但很快谷歌搜索显示有人显然是managed to do this using the SOAP-API。以下是论坛帖子中的相关代码:

    $this->proxy->call($this->session,
        'catalog_product_link.assign',
        array('configurable',
            $newConfigProdId, //This is the product ID of the configurable product
            $createdVariants, //This is an array of product IDs of simple products to associate to the configurable product
            array(ATTR_ID_COLOR, //This is an array of attribute IDs to create as superAttributes for the configurable product.
                ATTR_ID_SIZE //I've defined them as constants...
            )
        )
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-18
      • 1970-01-01
      相关资源
      最近更新 更多