// Fills the model by using the array $params
$premiumModel->
fromArray($params);
// find the shop-model by using the subShopId
/** @var Shop $shop */
$shop =
$this->
get('models'
)->
find(Shop::
class,
$params['shopId'
]);
$premiumModel->
setShop($shop);
/** @var Detail $productVariant */
$productVariant =
$this->
getArticleDetailRepository()->
findOneBy(['number' =>
$params['orderNumber'
]]);
$premiumModel->
setArticleDetail($productVariant);
// If the product is already set as a premium-product
$repository =
$this->
get('models'
)->
getRepository(Premium::
class);
$result =
$repository->
findByOrderNumber($params['orderNumber'
]);
$result =
$this->
get('models'
)->
toArray($result);
if (!
empty($result) &&
$params['shopId'
] ==
$result[0
]['shopId'
]) { $this->
View()->
assign(['success' => false, 'errorMsg' => 'The product already is a premium-product.'
]);
return;
}