Advertisement
Guest User

Untitled

a guest
May 21st, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <?php
  2.  
  3. use Magento\Catalog\Api\Data\ProductInterface;
  4. use Magento\Catalog\Api\ProductRepositoryInterface;
  5. use Psr\Log\LoggerInterface;
  6.  
  7. class Test
  8. {
  9. /**
  10. * @var LoggerInterface
  11. */
  12. private $logger;
  13.  
  14. public function __construct(LoggerInterface $logger)
  15. {
  16. $this->logger = $logger;
  17. }
  18.  
  19. public function beforeGetById(
  20. ProductRepositoryInterface $subject,
  21. $productId,
  22. $editMode = false,
  23. $storeId = null,
  24. $forceReload = false
  25. ) {
  26. $this->logger->info("Before");
  27. return [$productId, $editMode, $storeId, $forceReload];
  28. }
  29.  
  30. public function afterGetById(ProductRepositoryInterface $subject, ProductInterface $result)
  31. {
  32. $this->logger->info("After");
  33. return $result;
  34. }
  35.  
  36. public function aroundGetById(
  37. ProductRepositoryInterface $subject,
  38. callable $proceed,
  39. $productId,
  40. $editMode = false,
  41. $storeId = null,
  42. $forceReload = false
  43. ) {
  44. $this->logger->info("Around (before)");
  45. $result = $proceed($productId, $editMode, $storeId, $forceReload);
  46. $this->logger->info("Around (after)");
  47. return $result;
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement