5

我正在尝试将 Commerce 产品类型绑定到我自己的自定义类型节点(用作显示节点)。目标是在尽可能少的地方输入新数据。因此,我正在探索在创建另一种类型时基于规则创建一种类型。似乎两个方向都在起作用。不过,在这两者中,我更喜欢在用户创建自定义类型节点时自动创建商业产品,然后将其用作产品展示。

我想知道是否有人经历过这个选择并且可以推荐这个。另外,commerce_product_display_manager 模块是否必要?

4

2 回答 2

2

Commerce Product Display Manager 不是必需的,我已经让它工作了,但我从未使用过该模块。

我选择了保存产品后自动创建节点的路线。

以下是我的规则导出:

{ "rules_create_product_display" : {
    "LABEL" : "Create Product Display",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "entity" ],
    "ON" : [ "commerce_product_insert" ],
    "IF" : [
      { "data_is" : { "data" : [ "commerce-product:type" ], "value" : "**PRODUCT_TYPE**" } }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "node",
            "param_type" : "**NODE_TYPE**",
            "param_title" : "[commerce-product:title]",
            "param_author" : [ "commerce-product:creator" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:**PRODUCT_REFERENCE**" ],
          "value" : [ "commerce-product" ]
        }
      }
    ]
  }
}

您需要将自己的值替换为:

  • PRODUCT_TYPE(已创建的产品类型)
  • NODE_TYPE(正在创建的节点类型)
  • PRODUCT_REFERENCE(将引用创建的产品的字段)

抱歉,我现在不能花更多时间来提供更好的答案,如果您希望我详细说明使用 GUI 创建上述内容的过程,请告诉我

于 2011-08-01T09:17:38.053 回答
2

上面的例子很有用,但这里有一个更具体的例子:

{ "rules_create_product_display_on_product_creation" : {
    "LABEL" : "Create Product Display on Product creation",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "entity" ],
    "ON" : [ "commerce_product_insert" ],
    "IF" : [
      { "entity_is_of_type" : { "entity" : [ "commerce-product" ], "type" : "commerce_product" } }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "node",
            "param_type" : "product_display",
            "param_title" : "[commerce-product:title]",
            "param_author" : [ "commerce-product:creator" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:field-product:0" ],
          "value" : [ "commerce-product" ]
        }
      }
    ]
  }
}

The only problem I had was with the second action ("data_set")- it was important to select "entity-created:field-product:0", not the "entity-created:field-product" to make it work because we want to assign specific product and not a list of products.

This example is using the standard product display node type (product_display) but you can change it with the one you are using. Also have in mind that this is working only for one product type - for every product type a separated rule should be created. You may create also a rule for deleting the product display node when deleting the product. This rule is useful only when you have connection one product-one product display. If you need to add more products per product display (colors, images with different prices) then you have to use Commerce Bulk Product Creation module.

于 2012-04-12T12:11:18.187 回答