/** * @return Address - associated with parent having type set to billing */ public function getBillingAddress() { return $this->hasOne(Address::className(), ['id' => 'addressId'])->viaTable(CoreTables::TABLE_MODEL_ADDRESS, ['parentId' => 'id'], function ($query, $type = Address::TYPE_BILLING) { $modelAddress = CoreTables::TABLE_MODEL_ADDRESS; $query->onCondition("{$modelAddress}.parentType=:ptype AND {$modelAddress}.type=:type", [':ptype' => $this->addressType, ':type' => $type]); }); }
/** * @return Address - associated address */ public function getAddress() { return $this->hasOne(Address::className(), ['id' => 'addressId']); }
/** * @param integer $id * @return Address */ public static function findById($id) { return Address::findById($id); }
public static function copyToShipping($address, $parentId, $parentType, $order = 0) { $shippingAddress = new Address(); $shippingAddress->copyForUpdateFrom($address, ['countryId', 'provinceId', 'line1', 'line2', 'line3', 'city', 'zip', 'firstName', 'lastName', 'phone', 'email', 'fax']); return self::create($shippingAddress, $parentId, $parentType, Address::TYPE_SHIPPING, $order); }