모듈 서비스 계약을 사용해야합니다.
예를 들어 제품의 경우 ProductRepositoryInterface 를 사용해야합니다.
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Api;
/**
* @api
* @since 100.0.2
*/
interface ProductRepositoryInterface
{
/**
* Create product
*
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @param bool $saveOptions
* @return \Magento\Catalog\Api\Data\ProductInterface
* @throws \Magento\Framework\Exception\InputException
* @throws \Magento\Framework\Exception\StateException
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = false);
/**
* Get info about product by product SKU
*
* @param string $sku
* @param bool $editMode
* @param int|null $storeId
* @param bool $forceReload
* @return \Magento\Catalog\Api\Data\ProductInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function get($sku, $editMode = false, $storeId = null, $forceReload = false);
/**
* Get info about product by product id
*
* @param int $productId
* @param bool $editMode
* @param int|null $storeId
* @param bool $forceReload
* @return \Magento\Catalog\Api\Data\ProductInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getById($productId, $editMode = false, $storeId = null, $forceReload = false);
/**
* Delete product
*
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @return bool Will returned True if deleted
* @throws \Magento\Framework\Exception\StateException
*/
public function delete(\Magento\Catalog\Api\Data\ProductInterface $product);
/**
* @param string $sku
* @return bool Will returned True if deleted
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\StateException
*/
public function deleteById($sku);
/**
* Get product list
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return \Magento\Catalog\Api\Data\ProductSearchResultsInterface
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);
}
모듈 서비스 계약을 사용할 수없는 경우 ResourceModel을 사용하여 엔티티를 저장할 수 있습니다.