| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace app\modules\shop\models; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Yii; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * This is the model class for table "shipping_discount". | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @property integer $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @property integer $shipping_option_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @property integer $discount_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @property shippingOption $shippingOption | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 15 |  | View Code Duplication | class ShippingDiscount extends \app\modules\shop\models\AbstractDiscountType | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * getShippingOption | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * @return ShippingOption | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     public function getShippingOption() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         return $this->hasOne(ShippingOption::className(), ['id' => 'shipping_option_id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @inheritdoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     public function getFullName() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $model = $this->shippingOption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         return null === $model ? '(none)' : $model->name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @inheritdoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     public function checkDiscount(Discount $discount, Product $product = null, Order $order = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $odi = $order->orderDeliveryInformation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         if (null === $order || null === $odi) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $q = self::find()->where( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                 'discount_id' => $discount->id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                 'shipping_option_id' => $odi->shipping_option_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         )->count(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         if (0 === intval($q)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @inheritdoc | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |     public static function tableName() | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         return 'shipping_discount'; | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @inheritdoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     public function rules() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             [['shipping_option_id', 'discount_id'], 'required'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             [['shipping_option_id', 'discount_id'], 'integer'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * @inheritdoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     public function attributeLabels() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             'id' => Yii::t('app', 'ID'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             'shipping_option_id' => Yii::t('app', 'Shipping Option ID'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             'discount_id' => Yii::t('app', 'Discount ID'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 88 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |  | 
            
                        
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.