| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of EC-CUBE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Copyright(c) LOCKON CO.,LTD. All Rights Reserved. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * http://www.lockon.co.jp/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | namespace Eccube\Service\PurchaseFlow\Processor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Eccube\Entity\ItemInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Eccube\Entity\OrderItem; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Eccube\Service\PurchaseFlow\ItemProcessor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Eccube\Service\PurchaseFlow\ProcessResult; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Eccube\Service\PurchaseFlow\PurchaseContext; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * 販売価格の変更検知. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 24 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  | class PriceChangeValidator implements ItemProcessor | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |      * @param ItemInterface $item | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |      * @param PurchaseContext $context | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |      * @return ProcessResult | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 80 |  |     public function process(ItemInterface $item, PurchaseContext $context) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 80 |  |         if (!$item->isProduct()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 15 |  |             return ProcessResult::success(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 80 |  |         if ($item instanceof OrderItem) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 51 |  |             $price = $item->getPriceIncTax(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             // CartItem::priceは税込金額. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 80 |  |             $price = $item->getPrice(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 80 |  |         $realPrice = $item->getProductClass()->getPrice02IncTax(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 80 |  |         if ($price != $realPrice) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 1 |  |             $message = trans('cart.product.price.change', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 1 |  |                 ['%product%' => $item->getProductClass()->formatedProductName()]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 1 |  |             if ($item instanceof OrderItem) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 $item->setPrice($item->getProductClass()->getPrice02()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                 return ProcessResult::error($message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 // CartItem::priceは税込金額. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 1 |  |                 $item->setPrice($realPrice); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 1 |  |                 return ProcessResult::warn($message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 79 |  |         return ProcessResult::success(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 65 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |  |