Created
April 24, 2014 05:25
-
-
Save nvahalik/11242500 to your computer and use it in GitHub Desktop.
This particular set of gists gives you a framework for automating the creation of bundle groups from existing products. The first view is a rule which sets up the product bundle group. The second is a helper which creates a bundle item and ties it to a product. It gets called in a loop in the first rule. The last is an action which can be used t…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "rules_copy_product_to_a_bunde" : { | |
"LABEL" : "Create Bundle from a Product Display", | |
"PLUGIN" : "rule", | |
"OWNER" : "rules", | |
"REQUIRES" : [ "rules" ], | |
"USES VARIABLES" : { "orig_pbd" : { "label" : "Node as passed", "type" : "node" } }, | |
"IF" : [ | |
{ "entity_has_field" : { "entity" : [ "orig-pbd" ], "field" : "field_product" } } | |
], | |
"DO" : [ | |
{ "entity_create" : { | |
"USING" : { | |
"type" : "commerce_product", | |
"param_sku" : "BUNDLE-[orig-pbd:nid]", | |
"param_type" : "commerce_bundle_group", | |
"param_title" : "[orig-pdb:title] Bundle", | |
"param_creator" : [ "site:current-user" ], | |
"param_commerce_price" : { "value" : { "amount" : 0, "currency_code" : "USD" } } | |
}, | |
"PROVIDE" : { "entity_created" : { "created_pbg" : "Created Product Bundle Group" } } | |
} | |
}, | |
{ "LOOP" : { | |
"USING" : { "list" : [ "orig-pbd:field-product" ] }, | |
"ITEM" : { "orig_pdb_item" : "Current Product Display reference item" }, | |
"DO" : [ | |
{ "component_rules_create_bundle_item_from_product" : { | |
"USING" : { "orig_product" : [ "orig-pdb-item" ] }, | |
"PROVIDE" : { "pbi_int" : { "pbi_int" : "Bundle Item ID" } } | |
} | |
}, | |
{ "entity_fetch" : { | |
"USING" : { "type" : "commerce_bundle_item", "id" : [ "pbi-int" ] }, | |
"PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } } | |
} | |
}, | |
{ "list_add" : { | |
"list" : [ "created-pbg:commerce-bundle-items" ], | |
"item" : [ "entity-fetched" ] | |
} | |
} | |
] | |
} | |
}, | |
{ "data_set" : { | |
"data" : [ "created-pbg:commerce-bundle-unit-quantity" ], | |
"value" : "1" | |
} | |
}, | |
{ "entity_save" : { "data" : [ "created-pbg" ], "immediate" : 1 } } | |
] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "rules_create_bundle_item_from_product" : { | |
"LABEL" : "Create Bundle Item from Product", | |
"PLUGIN" : "rule", | |
"OWNER" : "rules", | |
"REQUIRES" : [ "rules" ], | |
"USES VARIABLES" : { | |
"orig_product" : { "label" : "Product", "type" : "commerce_product" }, | |
"pbi_int" : { "label" : "Bundle Item ID", "type" : "integer", "parameter" : false } | |
}, | |
"DO" : [ | |
{ "entity_create" : { | |
"USING" : { "type" : "commerce_bundle_item", "param_type" : "bundle_item" }, | |
"PROVIDE" : { "entity_created" : { "created_pbi" : "Created PBI" } } | |
} | |
}, | |
{ "data_set" : { "data" : [ "created-pbi:type" ], "value" : "bundle_item" } }, | |
{ "data_set" : { | |
"data" : [ "created-pbi:commerce-bundle-product" ], | |
"value" : [ "orig-product" ] | |
} | |
}, | |
{ "data_set" : { | |
"data" : [ "created-pbi:commerce-bundle-price" ], | |
"value" : [ "orig-product:commerce-price" ] | |
} | |
}, | |
{ "data_set" : { "data" : [ "created-pbi:status" ], "value" : 1 } }, | |
{ "entity_save" : { "data" : [ "created-pbi" ], "immediate" : 1 } }, | |
{ "data_set" : { "data" : [ "pbi-int" ], "value" : [ "created-pbi:item-id" ] } } | |
], | |
"PROVIDES VARIABLES" : [ "pbi_int" ] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "rules_create_a_bundle_from_a_node" : { | |
"LABEL" : "Copy into Bundle", | |
"PLUGIN" : "action set", | |
"OWNER" : "rules", | |
"REQUIRES" : [ "rules" ], | |
"USES VARIABLES" : { "node" : { "label" : "Node", "type" : "node" } }, | |
"ACTION SET" : [ | |
{ "component_rules_copy_product_to_a_bunde" : { "orig_pbd" : [ "node" ] } } | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment