<?php 
namespace PortalPeople\qvc\models;
use yii;
use backend\models\Accountsbe;

class Cart extends \backend\models\Cartsbe
{
    public function rules() : array
    {
        $rules = parent::rules();
        $rules[] = [['account_code'], 'default', 'value' => 'qvc001'];
        return $rules;
    }



    public function beforeSave($insert)
    {
        $account = Accountsbe::find()->where(['code' => 'qvc001'])->one() ?? throw new \RuntimeException("QVC Account not found");
        $qvcaddress = $account->addresses ? $account->addresses[0] : null;
        $this->fulladdresses['billing'] = $qvcaddress->attributes ?? [];
        return parent::beforeSave($insert);
    }
}