Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento使用PHP“选择可配置属性”_Php_Magento - Fatal编程技术网

Magento使用PHP“选择可配置属性”

Magento使用PHP“选择可配置属性”,php,magento,Php,Magento,我已经创建了新的可配置产品,并用PHP附加了它们的简单产品 现在,当我编辑任何可配置产品时,我会看到以下屏幕: 因此,在没有任何Magento文档的情况下,我应该在PHP中调用什么以编程方式执行与上面屏幕相同的功能 我在一些示例中看到了$configurable\u product->setConfigurableProductsData,但我并不认为它是我所需要的。你是对的,您正在创建可配置产品和子产品之间的关联/链接,但实际情况是,在创建可配置产品时,您没有设置基本上为该可配置产品设置超级属

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

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

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


我在一些示例中看到了$configurable\u product->setConfigurableProductsData,但我并不认为它是我所需要的。

你是对的,您正在创建可配置产品和子产品之间的关联/链接,但实际情况是,在创建可配置产品时,您没有设置基本上为该可配置产品设置超级属性信息的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();

    }

如果您有任何问题或需要进一步帮助,请告诉我。

您看到了这一点,因为您创建的configurabe产品和相关的简单产品有问题。再次检查您的脚本,并确保从magento的角度来看,脚本中的所有内容都很好。如果我选择其中一个属性,然后单击关联的产品,我可以看到我附加的简单产品。因此,该关联似乎在一个简单的产品级别上起作用,它只是没有在可配置产品上设置属性。这起作用,删除了“选择可配置属性”屏幕,但在我单击后端的“保存”之前,产品仍然不会显示在前端。这可以归结为索引,但我现在在一些产品上遇到问题,它们告诉我存在重复密钥$existingAtt=$product->getTypeInstance->getConfigurableAttributes;您可以粘贴完整的脚本吗?如何获取var$configAttrCodes?