次のコードでは、株式データを除外してすべての情報を保存できます。Magento 2で何か変更はありますか?
public function __construct(
ScopeConfigInterface $scopeConfig, CollectionFactory $product,
Magento\Catalog\Api\ProductRepositoryInterface $productRepository
) {
$this->scopeConfig = $scopeConfig;
$this->product = $product;
$this->productRepository = $productRepository;
}
public function update(\XXXXXX\XXXXXX\Api\Data\InventoryCollectionInterface $data) {
foreach ($data['list'] as $d) {
$product = $this->productRepository->getById($d['entity_id']);
$product->setStatus(($d['quantity'] > 0 ? 1 : 0));
$product->setUpc($d['upc']);
$product->setStockData(array(
'qty' => $d['quantity'],
'is_in_stock' => ($d['quantity'] > 0 ? 1 : 0)
));
$this->productRepository->save($product);
}
return "Done";
}