Skip to content

Commit

Permalink
Merge branch 'stable' into franz/changelogs_20201020
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-M-S authored Oct 20, 2020
2 parents 85b8787 + c38a42d commit f35496a
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 43 deletions.
94 changes: 51 additions & 43 deletions src/Extensions/Constants/ShopUrls.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,58 +456,66 @@ public function equals($urlA, $urlB)
*/
public function getTemplateType()
{
/** @var Request $request */
$request = pluginApp(Request::class);
return $this->fromMemoryCache('templateType', function() {

if ($request->has('templateType')) {
// template type is explicitly set via request param
return $request->get('templateType');
}
/** @var Request $request */
$request = pluginApp(Request::class);

/** @var ShopBuilderRequest $shopBuilderRequest */
$shopBuilderRequest = pluginApp(ShopBuilderRequest::class);
if($shopBuilderRequest->isShopBuilder() && ($previewType = $shopBuilderRequest->getPreviewContentType()) !== null) {
$previewTypeMap = [
'content' => RouteConfig::CATEGORY,
'checkout' => RouteConfig::CHECKOUT,
'myaccount' => RouteConfig::MY_ACCOUNT,
'singleitem' => RouteConfig::ITEM,
'categoryitem' => RouteConfig::CATEGORY,
'itemsearch' => RouteConfig::SEARCH,
'itemset' => RouteConfig::ITEM,
];
/** @var ShopBuilderRequest $shopBuilderRequest */
$shopBuilderRequest = pluginApp(ShopBuilderRequest::class);

return $previewTypeMap[$previewType] ?? RouteConfig::CATEGORY;
}
if ($request->has('templateType')) {
// template type is explicitly set via request param
return $request->get('templateType');
}

// detect template type from request uri
$url = Utils::makeRelativeUrl(
explode('?', $request->getRequestUri())[0],
$this->includeLanguage
);
// detect template type from request uri
$url = Utils::makeRelativeUrl(
explode('?', $request->getRequestUri())[0],
$this->includeLanguage
);

if (!strlen($url) || $url === '/') {
return RouteConfig::HOME;
}
if($shopBuilderRequest->isShopBuilder() && ($previewUri = $shopBuilderRequest->getPreviewUri()) !== null) {
$url = Utils::makeRelativeUrl($previewUri, $this->includeLanguage);
}

foreach (RouteConfig::ALL as $routeKey) {
if ($this->equals($url, $this->getShopUrl($routeKey))) {
// current page is a special linked page
return $routeKey;
if (!strlen($url) || $url === '/') {
return RouteConfig::HOME;
}
}

// match url pattern
if (preg_match('/(?:a\-\d+|_\d+|_\d+_\d+)\/?$/m', $url) === 1) {
return RouteConfig::ITEM;
} elseif (preg_match('/_t\d+\/?$/m', $url) === 1) {
return RouteConfig::TAGS;
} elseif (preg_match('/confirmation\/\d+\/([A-Za-z]|\d)+\/?/m', $url) === 1) {
return RouteConfig::CONFIRMATION;
}
foreach (RouteConfig::ALL as $routeKey) {
if ($this->equals($url, $this->getShopUrl($routeKey))) {
// current page is a special linked page
return $routeKey;
}
}

// match url pattern
if (preg_match('/(?:a\-\d+|_\d+|_\d+_\d+)\/?$/m', $url) === 1) {
return RouteConfig::ITEM;
} elseif (preg_match('/_t\d+\/?$/m', $url) === 1) {
return RouteConfig::TAGS;
} elseif (preg_match('/confirmation\/\d+\/([A-Za-z]|\d)+\/?/m', $url) === 1) {
return RouteConfig::CONFIRMATION;
}

if($shopBuilderRequest->isShopBuilder() && ($previewType = $shopBuilderRequest->getPreviewContentType()) !== null) {
$previewTypeMap = [
'content' => RouteConfig::CATEGORY,
'checkout' => RouteConfig::CHECKOUT,
'myaccount' => RouteConfig::MY_ACCOUNT,
'singleitem' => RouteConfig::ITEM,
'categoryitem' => RouteConfig::CATEGORY,
'itemsearch' => RouteConfig::SEARCH,
'itemset' => RouteConfig::ITEM,
];

return $previewTypeMap[$previewType] ?? RouteConfig::CATEGORY;
}

// template type cannot be determined
return RouteConfig::CATEGORY;
// template type cannot be determined
return RouteConfig::CATEGORY;
});
}

/**
Expand Down
24 changes: 24 additions & 0 deletions src/Services/BasketService.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,33 @@ function ($basketItem) {
$basketItems
);

if ($appendItemData) {
$basketItems = $this->removeInactiveBasketItems($basketItems);
}

return $basketItems;
}

private function removeInactiveBasketItems($basketItems = [])
{
$items = [];
foreach ($basketItems as $basketItem) {
if (is_null($basketItem['variation'])) {
$this->basketItemRepository->removeBasketItem($basketItem['id'], false);
} else {
$items[] = $basketItem;
}
}

if (count($items) != count($basketItems)) {
/** @var Dispatcher $pluginEventDispatcher */
$pluginEventDispatcher = pluginApp(Dispatcher::class);
$pluginEventDispatcher->fire(pluginApp(AfterBasketChanged::class), []);
}

return $items;
}

private function getSortedBasketItemOrderParams($basketItem): array
{
$newParams = [];
Expand Down
3 changes: 3 additions & 0 deletions src/Services/CustomerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ public function registerCustomer(array $contactData, $billingAddressData = null,

try {
if (!is_null($newBillingAddressData)) {
if ((isset($newBillingAddressData['gender']) && empty($newBillingAddressData['gender'])) || $newBillingAddressData['gender'] == 'company') {
$newBillingAddressData['gender'] = null;
}
AddressValidator::validateOrFail($newBillingAddressData);
}

Expand Down

0 comments on commit f35496a

Please sign in to comment.