refactoring part

This commit is contained in:
Annika Wolff 2019-12-17 13:11:02 +01:00
parent 54c06a94b1
commit 35fa80e91f
1 changed files with 15 additions and 1 deletions

View File

@ -55,8 +55,9 @@ class DownloadableLinkPurchasedRepository extends Repository
*/
public function saveLinks($orderItem)
{
if (stristr($orderItem->type,'downloadable') === false || ! isset($orderItem->additional['links']))
if (! $this->isDownloadableProduct($orderItem)) {
return;
}
foreach ($orderItem->additional['links'] as $linkId) {
if (! $productDownloadableLink = $this->productDownloadableLinkRepository->find($linkId))
@ -78,6 +79,19 @@ class DownloadableLinkPurchasedRepository extends Repository
}
}
/**
* Return true, if ordered item is valid downloadable product with links
*
* @param mixed $orderItem Webkul\Sales\Models\OrderItem;
* @return bool
*/
private function isDownloadableProduct($orderItem) : bool {
if (stristr($orderItem->type,'downloadable') !== false && isset($orderItem->additional['links'])) {
return true;
}
return false;
}
/**
* @param OrderItem $orderItem
* @param string $status