Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/cartforge.co/app/code/Amasty/MWishlist/Plugin/Wishlist/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/cartforge.co/app/code/Amasty/MWishlist/Plugin/Wishlist/Model/ItemPlugin.php
<?php

declare(strict_types=1);

/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Multiple Wishlist for Magento 2
 */

namespace Amasty\MWishlist\Plugin\Wishlist\Model;

use Amasty\MWishlist\Api\Data\WishlistInterface;
use Amasty\MWishlist\Api\WishlistRepositoryInterface;
use Amasty\MWishlist\Model\Source\Type;
use Magento\Checkout\Model\Cart;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Wishlist\Model\Item;
use Psr\Log\LoggerInterface;

class ItemPlugin
{
    /**
     * @var WishlistRepositoryInterface
     */
    private $wishlistRepository;

    /**
     * @var LoggerInterface
     */
    private $logger;

    /**
     * @var CustomerSession
     */
    private $customerSession;

    public function __construct(
        CustomerSession $customerSession,
        WishlistRepositoryInterface $wishlistRepository,
        LoggerInterface $logger
    ) {
        $this->wishlistRepository = $wishlistRepository;
        $this->logger = $logger;
        $this->customerSession = $customerSession;
    }

    /**
     * @param Item $subject
     * @param Cart $cart
     * @param bool $delete
     * @return array
     */
    public function beforeAddToCart(Item $subject, Cart $cart, bool $delete = false): array
    {
        try {
            if ($this->getWishlist((int)$subject->getWishlistId())->getType() == Type::REQUISITION) {
                $delete = false;
            }
        } catch (NoSuchEntityException $e) {
            $this->logger->error($e->getMessage());
        }

        $subject->getProduct()->setIsFromWishlist(true);

        return [$cart, $delete];
    }

    /**
     * @param int $wishlistId
     * @return WishlistInterface
     * @throws NoSuchEntityException
     */
    private function getWishlist(int $wishlistId): WishlistInterface
    {
        return $this->wishlistRepository->getById($wishlistId);
    }

    public function beforeSave(Item $subject): void
    {
        $groupId = $this->customerSession->getCustomerGroupId();
        $price = $subject->getProduct()->setCustomerGroupId($groupId)->getFinalPrice($subject->getQty());
        $subject->setProductPrice($price);
    }
}

Spamworldpro Mini