Skip to main content
added 143 characters in body
Source Link
Jimmy
  • 49
  • 2

You can try to add an around plugin on the save method of the following repositories:

  • \Magento\Quote\Api\CartItemRepositoryInterface
  • \Magento\Quote\Api\GuestCartItemRepositoryInterface

Something like:

public function aroundSave(
        \Magento\Quote\Api\CartItemRepositoryInterface $cartItemRepository, 
        callable $proceed, 
        \Magento\Quote\Api\Data\CartItemInterface $cartItem
    ) {
        $cartItem->setSku('YOUR SKU');
        return $proceed;
    }

Another solution is to add a preference for the same repositories, inherit original class and add a new implementation for the save method.

You can try to add an around plugin on the save method of the following repositories:

  • \Magento\Quote\Api\CartItemRepositoryInterface
  • \Magento\Quote\Api\GuestCartItemRepositoryInterface

Something like:

public function aroundSave(
        \Magento\Quote\Api\CartItemRepositoryInterface $cartItemRepository, 
        callable $proceed, 
        \Magento\Quote\Api\Data\CartItemInterface $cartItem
    ) {
        $cartItem->setSku('YOUR SKU');
        return $proceed;
    }

You can try to add an around plugin on the save method of the following repositories:

  • \Magento\Quote\Api\CartItemRepositoryInterface
  • \Magento\Quote\Api\GuestCartItemRepositoryInterface

Something like:

public function aroundSave(
        \Magento\Quote\Api\CartItemRepositoryInterface $cartItemRepository, 
        callable $proceed, 
        \Magento\Quote\Api\Data\CartItemInterface $cartItem
    ) {
        $cartItem->setSku('YOUR SKU');
        return $proceed;
    }

Another solution is to add a preference for the same repositories, inherit original class and add a new implementation for the save method.

Source Link
Jimmy
  • 49
  • 2

You can try to add an around plugin on the save method of the following repositories:

  • \Magento\Quote\Api\CartItemRepositoryInterface
  • \Magento\Quote\Api\GuestCartItemRepositoryInterface

Something like:

public function aroundSave(
        \Magento\Quote\Api\CartItemRepositoryInterface $cartItemRepository, 
        callable $proceed, 
        \Magento\Quote\Api\Data\CartItemInterface $cartItem
    ) {
        $cartItem->setSku('YOUR SKU');
        return $proceed;
    }