Magento API V2前端标签未定义。创建附加属性

时间:2013-12-25 17:07:05

标签: api magento c#-4.0

我正在通过Magento API V2创建附加属性,我无法设置前端标签,如果我创建没有前端标签的属性它创建属性和前端标签与属性代码相同,但是何时为前端标签设置自定义文本出错“前端标签未定义”

这是我的代码

 private void btnCreateAdditionalAttrib_Click(object sender, EventArgs e)
    {
        try
        {
            sessionID = MagentoConnectivity.connectMagento();
            string[] applyto = new string[1];
            applyto[0] = "simple";

            List<associativeEntity> thentities = new List<associativeEntity>
        {
            new associativeEntity { key = "store_id", value = "0" } ,
            new associativeEntity { key = "label", value = txtAttributeName.Text } 
        };

            catalogProductAttributeFrontendLabelEntity[] myFronendLabel = new catalogProductAttributeFrontendLabelEntity[2];



            myFronendLabel[0] = new catalogProductAttributeFrontendLabelEntity { label = "store_id", store_id = "1" };
            myFronendLabel[1] = new catalogProductAttributeFrontendLabelEntity { label = "label", store_id = txtAttributeName.Text };

            catalogProductAttributeEntityToCreate newAttribute = new catalogProductAttributeEntityToCreate
            {
                attribute_code = txtAttributeCode.Text,
                frontend_input = "text",
                scope = "1",
                default_value = "1",
                is_unique = 0,
                is_required = 0,
                apply_to = applyto,
                is_configurable = 0,
                is_searchable = 0,
                is_visible_in_advanced_search = 0,
                is_comparable = 0,
                is_used_for_promo_rules = 0,
                is_visible_on_front = 0,
                used_in_product_listing = 0,
                frontend_label = myFronendLabel

            };


            int x = MagentoConnectivity.magService.catalogProductAttributeCreate(sessionID, newAttribute);

            MessageBox.Show(x + "");
        }
        catch (Exception exp)
        {

            MessageBox.Show(exp.Message + "\n\n\n" + exp);
        }
    }

//这是PHP示例

http://www.magentocommerce.com/api/soap/catalog/catalogProductAttribute/product_attribute.create.html

    Request Example SOAP V2

<?php
//ini_set("soap.wsdl_cache_enabled", 0);

$client = new SoapClient('http://magentohost/api/v2_soap/?wsdl');

//V2
$session = $client->login('apiUser', 'apiKey');

// V2 WS-I Mode
//$response = $client->login(array('username' => 'apiUser', 'apiKey' => 'apiKey'));
//$session = $response->result;


//v2

$data = array(
   "attribute_code" => "test_attribute",
   "frontend_input" => "text",
   "scope" => "1",
   "default_value" => "1",
   "is_unique" => 0,
   "is_required" => 0,
   "apply_to" => array("simple"),
   "is_configurable" => 0,
   "is_searchable" => 0,
   "is_visible_in_advanced_search" => 0,
   "is_comparable" => 0,
   "is_used_for_promo_rules" => 0,
   "is_visible_on_front" => 0,
   "used_in_product_listing" => 0,
   "additional_fields" => array(),
   "frontend_label" => array(array("store_id" => "0", "label" => "some label"))
  );

$orders = $client->catalogProductAttributeCreate($session, $data);



//V2 WSI
//WSDL WSI Sample is not complete
//$result = $client->catalogProductAttributeCreate(array("sessionId" => $session, "data" => $data));
//$orders = $result->result->complexObjectArray;

echo 'Number of results: ' . count($orders) . '<br/>';
var_dump ($orders);
?>

2 个答案:

答案 0 :(得分:0)

问题是索引数组。

// app/code/Magento/Eav/Model/Resource/Entity/Attribute.php":207

$frontendLabel = $object->getFrontendLabel();
if (is_array($frontendLabel)) {
    $frontendLabel = array_values($frontendLabel); // add this line
    if (!isset($frontendLabel[0]) || is_null($frontendLabel[0]) || $frontendLabel[0] == '') {
        throw new \Magento\Core\Exception(__('Frontend label is not defined'));
    }

您可以在this pull request中看到更多详细信息。

答案 1 :(得分:0)

删除空格。将some label更改为some_label