public function findDefaultCombinationAndUndefault()
    {
        if (!empty($this->id)) {
            $defaultProductCombinations = Combination::find()
                ->where(['product_id' => $this->product_id, 'default' => true])
                ->andWhere(['!=', 'id', $this->id])
                ->all();
        } else {
            $defaultProductCombinations = Combination::find()
                ->where(['product_id' => $this->product_id, 'default' => true])
                ->all();
        }

        if (!empty($defaultProductCombinations)) {
            foreach ($defaultProductCombinations as $defaultProductCombination) {
                $defaultProductCombination->default = 0;
                if ($defaultProductCombination->validate()) $defaultProductCombination->save();
            }

        }
    }
public function findDefaultCombinationAndUndefault()
    {
        if (!empty($this->id)) {
            $defaultProductCombinations = Combination::find()
                ->where(['product_id' => $this->product_id, 'default' => true])
                ->andWhere(['!=', 'id', $this->id])
                ->all();
        } else {
            $defaultProductCombinations = Combination::find()
                ->where(['product_id' => $this->product_id, 'default' => true])
                ->all();
        }

        if (!empty($defaultProductCombinations)) {
            foreach ($defaultProductCombinations as $defaultProductCombination) {
                $defaultProductCombination->default = 0;
                if ($defaultProductCombination->validate()) $defaultProductCombination->save();
            }

        }
    }
public function findDefaultCombinationAndUndefault ( ) { if ( ! empty ( $ this -> id ) ) { $ defaultProductCombinations = Combination :: find ( ) -> where ( [ 'product_id' => $ this -> product_id , 'default' => true ] ) -> andWhere ( [ '!=' , 'id' , $ this -> id ] ) -> all ( ) ; } else { $ defaultProductCombinations = Combination :: find ( ) -> where ( [ 'product_id' => $ this -> product_id , 'default' => true ] ) -> all ( ) ; } if ( ! empty ( $ defaultProductCombinations ) ) { foreach ( $ defaultProductCombinations as $ defaultProductCombination ) { $ defaultProductCombination -> default = 0 ; if ( $ defaultProductCombination -> validate ( ) ) $ defaultProductCombination -> save ( ) ; } } }
Finds default combination for one product and makes it not default.
Finds default combination for one product and makes it not default .