MigrateDestinationCommerceProduct
The contrib module Commerce Migrate provides a few destination classes that extend the Entity API destination class provided by Migrate Extras.
When declaring the destination map, use "commerce_product" as the entity type (which is defined by the Commerce module suite), and "my_product_type" as the bundle type.
The following class imports commerce products. "sku" and "commerce_price" mappings are relevant to products. In the following example, "my_product_type" is the machine name of the commerce product type (defined via UI config), "import_database" is the import database name (defined in settings.php), and "import_data" is the table in that database where the import data exists. In the source map, "ItemNumber" is the unique identifier column in the table.
<?php
class AseEndoMigration extends Migration {
/**
* Doc comment.
*/
public function __construct() {
parent::__construct();
// The defintion of the columns.
$columns = array(
'Category',
'Name',
'ItemNumber',
'Description',
'USRetailPrice',
);
// Entity type, and bundle.
$this->destination = new MigrateDestinationCommerceProduct('commerce_product', 'my_product_type');
// Select all endodontic products.
Read moreExample: Programmatically create and update field collection with Entity API
The Entity API provides classes and methods / functions that make CRUD for entities much, much easier and less prone to errors and bugs.
The first example show the creation of a field collection entity that will be attached to a node that has a field collection field already defined for it through the Manage Fields tab of the node type creation / modification UI. The example shows creating the field collection entity (using the entity_create function of the Entity API, attaching it to a node, and using the Entity API then to set values of fields within the field collection.
<?php
// Code that would be here but is omitted loads a node called $my_node
// Nodes of the type that is $my_node have a field of the field collection
// type called field_text_files, which in turn is defined as having two
// fields called field_source_txt_filename and field_source_txt_content
// Begin by using the entity_create function to create a new entity of
// type field_collection_item. The second parameter to the function
// provides "an array of values to set, keyed by property name".
// In our example, the field in my_node that holds the field collection is