modules/acm_sku/src/StockManager.php
public function processStockMessage(array $stock, $store_id = 0) {
    // Sanity check.
    if (!isset($stock['sku']) || !strlen($stock['sku'])) {
      $this->logger->error('Invalid or empty product SKU. Stock message: @message', [
        '@message' => json_encode($stock),
      ]);

      return;
    }

    $langcode = NULL;

    if (empty($store_id) && isset($stock['store_id'])) {
      $store_id = $stock['store_id'];
    }

    // Check for stock is valid for current site.
    // If store id not available, we consider it as valid message.
    if ($store_id) {
      $langcode = $this->i18nHelper->getLangcodeFromStoreId($store_id);

      if (empty($langcode)) {
        // It could be for a different store/website, don't do anything.
        $this->logger->info('Ignored stock message for different store. Message: @message', [
          '@message' => json_encode($stock),
        ]);

        return;
      }
    }

    // We get qty in product data and quantity in stock push or from stock api.
    $quantity = array_key_exists('qty', $stock) ? $stock['qty'] : $stock['quantity'];
    $stock_status = isset($stock['is_in_stock']) ? (int) $stock['is_in_stock'] : 1;

    $changed = $this->updateStock($stock['sku'], $quantity, $stock_status);

    $this->logger->info('@operation stock for sku @sku. Message: @message', [
      '@operation' => $changed ? 'Updated' : 'Processed',
      '@sku' => $stock['sku'],
      '@message' => json_encode($stock),
    ]);
  }
public function processStockMessage(array $stock, $store_id = 0) {
    // Sanity check.
    if (!isset($stock['sku']) || !strlen($stock['sku'])) {
      $this->logger->error('Invalid or empty product SKU. Stock message: @message', [
        '@message' => json_encode($stock),
      ]);

      return;
    }

    $langcode = NULL;

    if (empty($store_id) && isset($stock['store_id'])) {
      $store_id = $stock['store_id'];
    }

    // Check for stock is valid for current site.
    // If store id not available, we consider it as valid message.
    if ($store_id) {
      $langcode = $this->i18nHelper->getLangcodeFromStoreId($store_id);

      if (empty($langcode)) {
        // It could be for a different store/website, don't do anything.
        $this->logger->info('Ignored stock message for different store. Message: @message', [
          '@message' => json_encode($stock),
        ]);

        return;
      }
    }

    // We get qty in product data and quantity in stock push or from stock api.
    $quantity = array_key_exists('qty', $stock) ? $stock['qty'] : $stock['quantity'];
    $stock_status = isset($stock['is_in_stock']) ? (int) $stock['is_in_stock'] : 1;

    $changed = $this->updateStock($stock['sku'], $quantity, $stock_status);

    $this->logger->info('@operation stock for sku @sku. Message: @message', [
      '@operation' => $changed ? 'Updated' : 'Processed',
      '@sku' => $stock['sku'],
      '@message' => json_encode($stock),
    ]);
  }
public function processStockMessage ( array $ stock , $ store_id = 0 ) { // Sanity check. if ( ! isset ( $ stock [ 'sku' ] ) || ! strlen ( $ stock [ 'sku' ] ) ) { $ this -> logger -> error ( 'Invalid or empty product SKU. Stock message: @message' , [ '@message' => json_encode ( $ stock ) , ] ) ; return ; } $ langcode = NULL ; if ( empty ( $ store_id ) && isset ( $ stock [ 'store_id' ] ) ) { $ store_id = $ stock [ 'store_id' ] ; } // Check for stock is valid for current site. // If store id not available, we consider it as valid message. if ( $ store_id ) { $ langcode = $ this -> i18nHelper -> getLangcodeFromStoreId ( $ store_id ) ; if ( empty ( $ langcode ) ) { // It could be for a different store/website, don't do anything. $ this -> logger -> info ( 'Ignored stock message for different store. Message: @message' , [ '@message' => json_encode ( $ stock ) , ] ) ; return ; } } // We get qty in product data and quantity in stock push or from stock api. $ quantity = array_key_exists ( 'qty' , $ stock ) ? $ stock [ 'qty' ] : $ stock [ 'quantity' ] ; $ stock_status = isset ( $ stock [ 'is_in_stock' ] ) ? ( int ) $ stock [ 'is_in_stock' ] : 1 ; $ changed = $ this -> updateStock ( $ stock [ 'sku' ] , $ quantity , $ stock_status ) ; $ this -> logger -> info ( '@operation stock for sku @sku. Message: @message' , [ '@operation' => $ changed ? 'Updated' : 'Processed' , '@sku' => $ stock [ 'sku' ] , '@message' => json_encode ( $ stock ) , ] ) ; }
Process stock message received in API.

@param array $stock
Stock data for particular SKU.
@param int $store_id
Store ID.

@throws \Exception
Process stock message received in API .