在以下代码中,我能够存储所有信息,但不包括库存数据。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";
}