| 
 | 1 | +diff --git a/vendor/magento/module-gift-card/Model/Catalog/Product/Price/Giftcard.php b/vendor/magento/module-gift-card/Model/Catalog/Product/Price/Giftcard.php  | 
 | 2 | +index 8988bd8eb02..aa8c589f54d 100644  | 
 | 3 | +--- a/vendor/magento/module-gift-card/Model/Catalog/Product/Price/Giftcard.php  | 
 | 4 | ++++ b/vendor/magento/module-gift-card/Model/Catalog/Product/Price/Giftcard.php  | 
 | 5 | +@@ -5,12 +5,20 @@  | 
 | 6 | +  */  | 
 | 7 | + namespace Magento\GiftCard\Model\Catalog\Product\Price;  | 
 | 8 | + | 
 | 9 | +-class Giftcard extends \Magento\Catalog\Model\Product\Type\Price  | 
 | 10 | ++use Magento\Catalog\Model\Product;  | 
 | 11 | ++use Magento\Catalog\Model\Product\Type\Price;  | 
 | 12 | ++use Magento\Store\Model\StoreManagerInterface;  | 
 | 13 | ++use Magento\GiftCard\Model\Catalog\Product\Type\Giftcard as GiftCardType;  | 
 | 14 | ++  | 
 | 15 | ++/**  | 
 | 16 | ++ * Gift card product type price model  | 
 | 17 | ++ *  | 
 | 18 | ++ * @SuppressWarnings(PHPMD.CookieAndSessionMisuse)  | 
 | 19 | ++ */  | 
 | 20 | ++class Giftcard extends Price  | 
 | 21 | + {  | 
 | 22 | +     /**  | 
 | 23 | +-     * Store manager  | 
 | 24 | +-     *  | 
 | 25 | +-     * @var \Magento\Store\Model\StoreManagerInterface  | 
 | 26 | ++     * @var StoreManagerInterface  | 
 | 27 | +      */  | 
 | 28 | +     protected $_storeManager;  | 
 | 29 | + | 
 | 30 | +@@ -29,7 +37,7 @@ class Giftcard extends \Magento\Catalog\Model\Product\Type\Price  | 
 | 31 | +     /**  | 
 | 32 | +      * Return price of the specified product  | 
 | 33 | +      *  | 
 | 34 | +-     * @param \Magento\Catalog\Model\Product $product  | 
 | 35 | ++     * @param Product $product  | 
 | 36 | +      * @return float  | 
 | 37 | +      */  | 
 | 38 | +     public function getPrice($product)  | 
 | 39 | +@@ -52,27 +60,14 @@ class Giftcard extends \Magento\Catalog\Model\Product\Type\Price  | 
 | 40 | +      * Retrieve product final price  | 
 | 41 | +      *  | 
 | 42 | +      * @param int $qty  | 
 | 43 | +-     * @param \Magento\Catalog\Model\Product $product  | 
 | 44 | ++     * @param Product $product  | 
 | 45 | +      * @return float  | 
 | 46 | +      */  | 
 | 47 | +     public function getFinalPrice($qty, $product)  | 
 | 48 | +     {  | 
 | 49 | +         $finalPrice = $product->getPrice();  | 
 | 50 | +         if ($product->hasCustomOptions()) {  | 
 | 51 | +-            $customOption = $product->getCustomOption('giftcard_amount');  | 
 | 52 | +-            if ($customOption) {  | 
 | 53 | +-                $amounts = $product->getGiftcardAmounts();  | 
 | 54 | +-                if (!empty($amounts) && count($amounts) === 1) {  | 
 | 55 | +-                    $optionValue = $product->getGiftcardAmounts()[0]['value'];  | 
 | 56 | +-                    if ($optionValue !== $customOption->getValue()) {  | 
 | 57 | +-                        $finalPrice += $optionValue;  | 
 | 58 | +-                    } else {  | 
 | 59 | +-                        $finalPrice += $customOption->getValue();  | 
 | 60 | +-                    }  | 
 | 61 | +-                } else {  | 
 | 62 | +-                    $finalPrice += $customOption->getValue();  | 
 | 63 | +-                }  | 
 | 64 | +-            }  | 
 | 65 | ++            $finalPrice = $this->getFinalPriceWithCustomOptions($product, $finalPrice);  | 
 | 66 | +         }  | 
 | 67 | +         $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);  | 
 | 68 | + | 
 | 69 | +@@ -83,7 +78,7 @@ class Giftcard extends \Magento\Catalog\Model\Product\Type\Price  | 
 | 70 | +     /**  | 
 | 71 | +      * Load and set gift card amounts into product object  | 
 | 72 | +      *  | 
 | 73 | +-     * @param \Magento\Catalog\Model\Product $product  | 
 | 74 | ++     * @param Product $product  | 
 | 75 | +      * @return array  | 
 | 76 | +      */  | 
 | 77 | +     public function getAmounts($product)  | 
 | 78 | +@@ -97,13 +92,13 @@ class Giftcard extends \Magento\Catalog\Model\Product\Type\Price  | 
 | 79 | +             }  | 
 | 80 | +         }  | 
 | 81 | + | 
 | 82 | +-        return $prices ? $prices : [];  | 
 | 83 | ++        return $prices ?: [];  | 
 | 84 | +     }  | 
 | 85 | + | 
 | 86 | +     /**  | 
 | 87 | +      * Return minimal amount for Giftcard product  | 
 | 88 | +      *  | 
 | 89 | +-     * @param \Magento\Catalog\Model\Product $product  | 
 | 90 | ++     * @param Product $product  | 
 | 91 | +      * @return float  | 
 | 92 | +      */  | 
 | 93 | +     public function getMinAmount($product)  | 
 | 94 | +@@ -115,7 +110,7 @@ class Giftcard extends \Magento\Catalog\Model\Product\Type\Price  | 
 | 95 | +     /**  | 
 | 96 | +      * Return maximal amount for Giftcard product  | 
 | 97 | +      *  | 
 | 98 | +-     * @param \Magento\Catalog\Model\Product $product  | 
 | 99 | ++     * @param Product $product  | 
 | 100 | +      * @return float  | 
 | 101 | +      */  | 
 | 102 | +     public function getMaxAmount($product)  | 
 | 103 | +@@ -127,7 +122,7 @@ class Giftcard extends \Magento\Catalog\Model\Product\Type\Price  | 
 | 104 | +     /**  | 
 | 105 | +      * Fill in $_amountCache or return precalculated sorted values for amounts  | 
 | 106 | +      *  | 
 | 107 | +-     * @param \Magento\Catalog\Model\Product $product  | 
 | 108 | ++     * @param Product $product  | 
 | 109 | +      * @return array  | 
 | 110 | +      */  | 
 | 111 | +     public function getSortedAmounts($product)  | 
 | 112 | +@@ -150,7 +145,7 @@ class Giftcard extends \Magento\Catalog\Model\Product\Type\Price  | 
 | 113 | +     /**  | 
 | 114 | +      * Fill in $_minMaxCache or return precalculated values for min, max  | 
 | 115 | +      *  | 
 | 116 | +-     * @param \Magento\Catalog\Model\Product $product  | 
 | 117 | ++     * @param Product $product  | 
 | 118 | +      * @return array  | 
 | 119 | +      * @SuppressWarnings(PHPMD.CyclomaticComplexity)  | 
 | 120 | +      */  | 
 | 121 | +@@ -194,4 +189,35 @@ class Giftcard extends \Magento\Catalog\Model\Product\Type\Price  | 
 | 122 | +         }  | 
 | 123 | +         return $this->_minMaxCache[$product->getId()];  | 
 | 124 | +     }  | 
 | 125 | ++  | 
 | 126 | ++    /**  | 
 | 127 | ++     * Retrieve product final price with custom options  | 
 | 128 | ++     *  | 
 | 129 | ++     * @param Product $product  | 
 | 130 | ++     * @param float $finalPrice  | 
 | 131 | ++     * @return mixed  | 
 | 132 | ++     */  | 
 | 133 | ++    private function getFinalPriceWithCustomOptions(Product $product, $finalPrice)  | 
 | 134 | ++    {  | 
 | 135 | ++        $customOption = $product->getCustomOption('giftcard_amount');  | 
 | 136 | ++        $isCustomGiftCard = $product->getCustomOption(GiftCardType::GIFTCARD_AMOUNT_IS_CUSTOM);  | 
 | 137 | ++        if ($customOption) {  | 
 | 138 | ++            $amounts = $product->getGiftcardAmounts();  | 
 | 139 | ++            if (!empty($amounts) && count($amounts) === 1) {  | 
 | 140 | ++                $optionValue = $product->getGiftcardAmounts()[0]['value'];  | 
 | 141 | ++                if ($isCustomGiftCard && $isCustomGiftCard->getValue()) {  | 
 | 142 | ++                    $finalPrice += $customOption->getValue();  | 
 | 143 | ++                } else {  | 
 | 144 | ++                    if ($optionValue !== $customOption->getValue()) {  | 
 | 145 | ++                        $finalPrice += $optionValue;  | 
 | 146 | ++                    } else {  | 
 | 147 | ++                        $finalPrice += $customOption->getValue();  | 
 | 148 | ++                    }  | 
 | 149 | ++                }  | 
 | 150 | ++            } else {  | 
 | 151 | ++                $finalPrice += $customOption->getValue();  | 
 | 152 | ++            }  | 
 | 153 | ++        }  | 
 | 154 | ++        return $finalPrice;  | 
 | 155 | ++    }  | 
 | 156 | + }  | 
 | 157 | +diff --git a/vendor/magento/module-gift-card/Model/Catalog/Product/Type/Giftcard.php b/vendor/magento/module-gift-card/Model/Catalog/Product/Type/Giftcard.php  | 
 | 158 | +index 9e4f4245595..cb58f914acb 100644  | 
 | 159 | +--- a/vendor/magento/module-gift-card/Model/Catalog/Product/Type/Giftcard.php  | 
 | 160 | ++++ b/vendor/magento/module-gift-card/Model/Catalog/Product/Type/Giftcard.php  | 
 | 161 | +@@ -17,7 +17,9 @@ use Magento\Store\Model\Store;  | 
 | 162 | +  */  | 
 | 163 | + class Giftcard extends \Magento\Catalog\Model\Product\Type\AbstractType  | 
 | 164 | + {  | 
 | 165 | +-    const TYPE_GIFTCARD = 'giftcard';  | 
 | 166 | ++    public const TYPE_GIFTCARD = 'giftcard';  | 
 | 167 | ++  | 
 | 168 | ++    public const GIFTCARD_AMOUNT_IS_CUSTOM = 'giftcard_amount_is_custom';  | 
 | 169 | + | 
 | 170 | +     /**  | 
 | 171 | +      * Whether product quantity is fractional number or not  | 
 | 172 | +@@ -228,6 +230,12 @@ class Giftcard extends \Magento\Catalog\Model\Product\Type\AbstractType  | 
 | 173 | +             $product->addCustomOption('giftcard_recipient_email', $buyRequest->getGiftcardRecipientEmail(), $product);  | 
 | 174 | +         }  | 
 | 175 | + | 
 | 176 | ++        if ($buyRequest->getGiftcardAmount() === 'custom') {  | 
 | 177 | ++            $product->addCustomOption(self::GIFTCARD_AMOUNT_IS_CUSTOM, true, $product);  | 
 | 178 | ++        } else {  | 
 | 179 | ++            $product->addCustomOption(self::GIFTCARD_AMOUNT_IS_CUSTOM, false, $product);  | 
 | 180 | ++        }  | 
 | 181 | ++  | 
 | 182 | +         $messageAllowed = false;  | 
 | 183 | +         if ($product->getUseConfigAllowMessage()) {  | 
 | 184 | +             $messageAllowed = $this->_scopeConfig->isSetFlag(  | 
 | 185 | +@@ -425,6 +433,7 @@ class Giftcard extends \Magento\Catalog\Model\Product\Type\AbstractType  | 
 | 186 | +             $messageAmount = $this->priceCurrency->convertAndFormat($minAmount, false);  | 
 | 187 | +             throw new \Magento\Framework\Exception\LocalizedException(__('Gift Card min amount is %1', $messageAmount));  | 
 | 188 | +         }  | 
 | 189 | ++        return 0;  | 
 | 190 | +     }  | 
 | 191 | + | 
 | 192 | +     /**  | 
 | 193 | +@@ -539,7 +548,9 @@ class Giftcard extends \Magento\Catalog\Model\Product\Type\AbstractType  | 
 | 194 | +      * @return void  | 
 | 195 | +      * @SuppressWarnings(PHPMD.UnusedFormalParameter)  | 
 | 196 | +      */  | 
 | 197 | ++    // @codingStandardsIgnoreStart  | 
 | 198 | +     public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $product)  | 
 | 199 | +     {  | 
 | 200 | +     }  | 
 | 201 | ++    // @codingStandardsIgnoreEnd  | 
 | 202 | + }  | 
0 commit comments