At present, there is no support for importing stores with Feeds or Commerce Feeds. I made a feature request in the Commerce Feeds issue queue.
In the meantime, I set up a feed type for importing Commerce stores that uses mappings for every field except address (because there is no support for address).
I want to be able to update my stores, so I am now using this feed to update them, but creating the store entities manually in hook_module_update()
as shown below.
use \Drupal\commerce_store\Entity\Store;
MYMODULE_update_9001() {
// The default address value to use.
$address_default = [
'country_code' => 'JP',
'administrative_area' => 'Tokyo',
'locality' => 'Place',
'postal_code' => '111-1111',
'address_line1' => 'Someplace',
'address_line2' => 'Somewhere',
];
// Find the ID for the store feed type that we want to use to update this store.
$store_feed_id_query =
\Drupal::entityQuery('feeds_feed')
->condition('type', 'store_feed_type_machine_name');
$store_feed_result = $store_feed_id_query->execute();
$store_feed_id = 0;
if (isset($store_feed_result)) {
// Need to iterate through the results; there should only be one result, but if there are multiple, take the most recent.
foreach ($store_feed_result as $only_result) {
$store_feed_id = $only_result;
}
}
if ($store_feed_id > 0) {
$store = Store::create([
'type' => 'store_type_machine_name',
'name' => 'My Awesome Store',
'mail' => '[email protected]',
'default_currency' => 'JPY',
'address' => $address_default,
'timezone' => 'Asia/Tokyo',
'is_default' => 1,
'path' => '/store',
'uid' => 2,
]);
$store->feeds_item->target_id = $store_feed_id;
$store->feeds_item->guid = 'my-store-id'; // Optional, only set if you are using GUID to make your feed unique.
$store->save();
} else {
throw new \Exception("Failed to get store feed id: $store_feed_id");
}
}
Note that in my mappings for the Feeds Item field, I have set GUID to be the unique value. This allows me to use my feed type to update the store values. More information on working with Feed Items programmatically.