Skip to content

Instantly share code, notes, and snippets.

@nvahalik
Created April 24, 2014 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nvahalik/11242500 to your computer and use it in GitHub Desktop.
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…
{ "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 } }
]
}
}
{ "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