Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPD-50061 Import From Whish Lists does not work when Maximum Number of Open Orders per Account is set to 1 #5977

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,36 @@

/**
* @author Brian I. Kim
* @author Crescenzo Rega
*/
public class CommerceOrderThreadLocal {

public static boolean isDeleteInProcess() {
return _deleteInProcess.get();
}

public static boolean isSkipValidateAccountOrdersLimit() {
return _skipValidateAccountOrdersLimit.get();
}

public static void setDeleteInProcess(boolean deleteInProcess) {
_deleteInProcess.set(deleteInProcess);
}

public static void setSkipValidateAccountOrdersLimit(
boolean skipValidateAccountOrdersLimit) {

_skipValidateAccountOrdersLimit.set(skipValidateAccountOrdersLimit);
}

private static final ThreadLocal<Boolean> _deleteInProcess =
new CentralizedThreadLocal<>(
CommerceOrderThreadLocal.class + "._deleteInProcess",
() -> Boolean.FALSE);
private static final ThreadLocal<Boolean> _skipValidateAccountOrdersLimit =
new CentralizedThreadLocal<>(
CommerceReturnThreadLocal.class +
"._skipValidateAccountOrdersLimit",
() -> Boolean.FALSE);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.liferay.commerce.exception.CommerceOrderValidatorException;
import com.liferay.commerce.model.CommerceOrder;
import com.liferay.commerce.model.CommerceOrderItem;
import com.liferay.commerce.order.CommerceOrderThreadLocal;
import com.liferay.commerce.order.importer.item.CommerceOrderImporterItem;
import com.liferay.commerce.order.importer.item.CommerceOrderImporterItemImpl;
import com.liferay.commerce.price.CommerceOrderPriceCalculation;
Expand Down Expand Up @@ -52,6 +53,8 @@ public static List<CommerceOrderImporterItem> getCommerceOrderImporterItems(
UserLocalService userLocalService)
throws Exception {

CommerceOrderThreadLocal.setSkipValidateAccountOrdersLimit(true);

CommerceOrder tempCommerceOrder = commerceOrderService.addCommerceOrder(
commerceOrder.getGroupId(), commerceOrder.getCommerceAccountId(),
commerceOrder.getCommerceCurrencyCode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2785,6 +2785,12 @@ private void _validateAccountOrdersLimit(
long commerceChannelGroupId, long commerceAccountId)
throws PortalException {

if (CommerceOrderThreadLocal.isSkipValidateAccountOrdersLimit()) {
CommerceOrderThreadLocal.setSkipValidateAccountOrdersLimit(false);

return;
}

Group group = _groupLocalService.getGroup(commerceChannelGroupId);

int pendingCommerceOrdersCount =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.liferay.commerce.exception.CommerceOrderAccountLimitException;
import com.liferay.commerce.model.CommerceAddress;
import com.liferay.commerce.model.CommerceOrder;
import com.liferay.commerce.order.CommerceOrderThreadLocal;
import com.liferay.commerce.order.engine.CommerceOrderEngine;
import com.liferay.commerce.product.constants.CommerceChannelConstants;
import com.liferay.commerce.product.model.CommerceChannel;
Expand Down Expand Up @@ -987,6 +988,64 @@ public void testGetPlacedCommerceOrder() throws Exception {
_accountEntryLocalService.deleteAccountEntry(accountEntry);
}

@Test
public void testSkipValidateAccountOrdersLimit() throws Exception {
Settings settings = FallbackKeysSettingsUtil.getSettings(
new GroupServiceSettingsLocator(
_commerceChannel.getGroupId(),
CommerceConstants.SERVICE_NAME_COMMERCE_ORDER_FIELDS));

ModifiableSettings modifiableSettings =
settings.getModifiableSettings();

modifiableSettings.setValue("accountCartMaxAllowed", "1");

modifiableSettings.store();

AccountEntry accountEntry =
CommerceAccountTestUtil.addBusinessAccountEntry(
_user.getUserId(), "Test Business Account", null, null,
new long[] {_user.getUserId()}, null, _serviceContext);

long commerceChannelGroupId = _commerceChannel.getGroupId();

_commerceOrderLocalService.addCommerceOrder(
_user.getUserId(), commerceChannelGroupId,
accountEntry.getAccountEntryId(), _commerceCurrency.getCode(), 0);

try {
_commerceOrderLocalService.addCommerceOrder(
_user.getUserId(), commerceChannelGroupId,
accountEntry.getAccountEntryId(), _commerceCurrency.getCode(),
0);
}
catch (CommerceOrderAccountLimitException
commerceOrderAccountLimitException) {

Assert.assertNotNull(commerceOrderAccountLimitException);
}

Assert.assertEquals(
1,
_commerceOrderService.getPendingCommerceOrdersCount(
commerceChannelGroupId, accountEntry.getAccountEntryId(),
StringPool.BLANK));

CommerceOrderThreadLocal.setSkipValidateAccountOrdersLimit(true);

_commerceOrderLocalService.addCommerceOrder(
_user.getUserId(), commerceChannelGroupId,
accountEntry.getAccountEntryId(), _commerceCurrency.getCode(), 0);

Assert.assertEquals(
2,
_commerceOrderService.getPendingCommerceOrdersCount(
commerceChannelGroupId, accountEntry.getAccountEntryId(),
StringPool.BLANK));

_accountEntries.add(accountEntry);
}

@Test
public void testValidateAccountOrdersLimit() throws Exception {
frutillaRule.scenario(
Expand Down