php - Magento 'Select Configurable Attributes' 与 PHP

标签 php magento

我创建了新的可配置产品,并用 PHP 附加了他们的简单产品。

现在,当我编辑任何可配置的产品时,我会看到这个屏幕:

Magento Select Configurable Attributes screen in admin

那么在没有任何 Magento 文档的情况下,我应该在 PHP 中调用什么来以编程方式执行与上面屏幕相同的功能?

我已经看到一些示例中使用了 $configurable_product->setConfigurableProductsData(),但我认为这不是我需要的。

最佳答案

您是对的,您正在创建可配置产品和子产品之间的关联/链接,但实际情况是,当您创建可配置产品时,您没有设置基本上设置 super 属性的 setConfigurableAttributesData该可配置产品的信息。

    foreach($configAttrCodes as $attrCode){

        $super_attribute= Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product',$attrCode->code);
        $configurableAtt = Mage::getModel('catalog/product_type_configurable_attribute')->setProductAttribute($super_attribute);

        $newAttributes[] = array(
           'id'             => $configurableAtt->getId(),
           'label'          => $configurableAtt->getLabel(),
           'position'       => $super_attribute->getPosition(),
           'values'         => $configurableAtt->getPrices() ? $configProduct->getPrices() : array(),
           'attribute_id'   => $super_attribute->getId(),
           'attribute_code' => $super_attribute->getAttributeCode(),
           'frontend_label' => $super_attribute->getFrontend()->getLabel(),
        );
    }

    $existingAtt = $product->getTypeInstance()->getConfigurableAttributes();

    if(empty($existingAtt) && !empty($newAttributes)){
        $configProduct->setCanSaveConfigurableAttributes(true);
        $configProduct->setConfigurableAttributesData($newAttributes);
        $configProduct->save();

    }

这是一个小片段应该可以帮助您,如果您有任何问题或需要进一步的帮助,请告诉我。

关于php - Magento 'Select Configurable Attributes' 与 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8538790/

相关文章:

Magento 2 - 以编程方式创建订单并使用自定义选项添加产品

php - Paypal PDT 没有返回所有变量

php - 更改 mysql 中的 htmlentities

magento - 在订单确认电子邮件中使用客户的名字

magento 和 Paypal 整合

magento-1.4 - 我在 Magento 中获得了两次区 block ?

php - 如何为laravel本地存储生成临时文件下载url?

php - 为什么这个 PHP 代码不起作用?

php - ExpressCheckout IPN 无效响应状态 403

php - 在 Magento 中使用缩略图切换基本图像