Add migration support - create destination plugin

Created on 14 November 2018, over 6 years ago
Updated 16 February 2023, about 2 years ago

As a site owner migrating from Drupal 7, I need a way to set the stock levels when products are imported. Ideally, we'd have a migration plugin for this, but in the interim, I've created a Drush command to handle this with the following code:

use Drupal\commerce_product\Entity\ProductVariation;
use Drupal\commerce_stock\StockTransactionsInterface;

function drush_my_migrate_add_commerce_stock() {
  $stockServiceManager = \Drupal::service('commerce_stock.service_manager');
  $variations = \Drupal::entityQuery('commerce_product_variation')
    ->condition('sku', 'MYSKU')
    ->execute();
  $variation = ProductVariation::load(reset($variations));
  $stockServiceManager->createTransaction($variation, 1, '', 10, NULL, NULL, StockTransactionsInterface::STOCK_IN, ['data' => []]);
}
πŸ“Œ Task
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States cameron prince

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024