Skip to content

Commit

Permalink
Add commerce-on-lightnin-orchestration and sfdx-1commerce-plugin comm…
Browse files Browse the repository at this point in the history
…ands
  • Loading branch information
unandyala committed Nov 14, 2022
1 parent 206af0c commit 07c85a4
Show file tree
Hide file tree
Showing 17 changed files with 783 additions and 57 deletions.
101 changes: 87 additions & 14 deletions README.md

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,32 @@
"targetdevhubusername",
"targetusername"
]
},
{
"command": "commerce:scratchorg:create",
"plugin": "@salesforce/commerce",
"flags": [
"apiversion",
"targetdevhubusername",
"json",
"loglevel",
"prompt",
"username",
"alias",
"wait",
"type"
]
},
{
"command": "commerce:search:start",
"plugin": "@salesforce/commerce",
"flags": [
"store-name",
"store-id",
"targetusername",
"apiversion",
"json",
"loglevel"
]
}
]
27 changes: 27 additions & 0 deletions config/b2b-project-scratch-def.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"orgName": "Test B2B Company",
"edition": "Developer",
"features": ["Communities", "B2BCommerce", "OrderManagement", "EnableSetPasswordInApi"],
"settings": {
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
},
"experienceBundleSettings": {
"enableExperienceBundleMetadata": true
},
"communitiesSettings": {
"enableNetworksEnabled": true
},
"orderManagementSettings": {
"enableOrderManagement": true
},
"orderSettings": {
"enableOrders": true,
"enableEnhancedCommerceOrders": true,
"enableOptionalPricebook": true
},
"commerceSettings": {
"commerceEnabled": true
}
}
}
30 changes: 30 additions & 0 deletions config/b2c-project-scratch-def.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"orgName": "Test B2C Company",
"edition": "Developer",
"features": ["Communities", "B2CCommerceGMV", "PersonAccounts", "EnableSetPasswordInApi"],
"settings": {
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
},
"experienceBundleSettings": {
"enableExperienceBundleMetadata": true
},
"communitiesSettings": {
"enableNetworksEnabled": true
},
"orderManagementSettings": {
"enableOrderManagement": true
},
"orderSettings": {
"enableOrders": true,
"enableEnhancedCommerceOrders": true,
"enableOptionalPricebook": true
},
"commerceSettings": {
"commerceEnabled": true
},
"languageSettings": {
"enableTranslationWorkbench": true
}
}
}
37 changes: 37 additions & 0 deletions config/both-project-scratch-def.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"orgName": "Test B2B and B2C Company",
"edition": "Developer",
"features": [
"Communities",
"B2BCommerce",
"B2CCommerceGMV",
"PersonAccounts",
"OrderManagement",
"EnableSetPasswordInApi"
],
"settings": {
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
},
"experienceBundleSettings": {
"enableExperienceBundleMetadata": true
},
"communitiesSettings": {
"enableNetworksEnabled": true
},
"orderManagementSettings": {
"enableOrderManagement": true
},
"orderSettings": {
"enableOrders": true,
"enableEnhancedCommerceOrders": true,
"enableOptionalPricebook": true
},
"commerceSettings": {
"commerceEnabled": true
},
"languageSettings": {
"enableTranslationWorkbench": true
}
}
}
44 changes: 44 additions & 0 deletions messages/scratchorg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"devHubFlags": {
"hubOrgAdminUsernameDescription": "username of the hub org admin"
},
"createFlags": {
"scratchOrgAdminUsernameDescription": "username of the admin to associate with the scratch org.",
"scratchOrgStoreNameDescription": "Name of scratch org store",
"scratchOrgStoreNumberDescription": "Which store to create from config file scratchOrgs list -1 for all stores",
"isB2cLiteAccessPermNeededDescription": "Should the script run sfdx force:org:open and wait for you to save B2CLiteAccessPerm?",
"scratchOrgAliasDescription": "Alias name for this scratch org",
"apiVersionDescription": "Version of current Salesforce",
"wait": "The streaming client socket timeout (in minutes)"

},
"create": {
"cmdDescription": "Create a scratch org",
"waitingForStringToLoad": "Waiting for %s to load",
"permsEnabled": "Perms enabled",
"permsDisabled": "Perms disabled",
"usingScratchOrgAdmin": "Using scratch org admin %s",
"devhubSetupWasNotCompletedSuccessfully": "Devhub setup was not completed successfully. Please complete devhub setup before attempting to create a scratch org.'",
"completedCreatingScratchOrg": "Completed creating scratch org.",
"allDoneProceedCreatingNewStore": "All done, you can proceed with creating a new store %s",
"orgExists": "Org already exists: ",
"preparingResourcesEtc": "Preparing resources (apex, profiles, email templates, etc.)",
"creatingNewScratchOrgInfo": "Creating a new scratch org, note that you can create maximum of 3 scratch orgs per day, so this may fail if you have more.\n",
"apiVersion": "API version: %s\n",
"devhubUsername": "Devhub Username: %s\n",
"scratchOrgAdminUsername": "Scratch Org Admin Username: %s\n",
"thisMayTakeAFewMins": "This may take a few minutes...\n",
"creatingNewScratchOrg": "Creating a new scratch org",
"using": "Using %s",
"successfulOrgCreation": "Org Creation Successful",
"failureOrgCreation": "Org Creation Failure",
"sleepingBeforeCheckingIfOrgIsCreated": "Sleeping before checking if org is created yet.",
"waitedTimeStillNoOrgCreated": "Waited %s and still no org created",
"scratchOrgNowExists": "Scratch org now exists",
"errorOccurredMightNeedDevhubAuth\n": "Error Occurred, might be because you need to devhub auth\n",
"authFailed": "Auth Failed",
"isAlreadyInUse": "is already in use",
"errorOccurredDuringOrgCreateMightNeedTMPAuth": "Error Occurred during Org Create, might need to TMP Auth\n",
"pleaseTryAgain": "Please try again"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/commerce",
"version": "242.0.4",
"version": "242.0.12",
"author": "Jonathan Arndt",
"bugs": "https://github.com/forcedotcom/commerce-on-lightning/issues",
"dependencies": {
Expand Down Expand Up @@ -95,6 +95,7 @@
"payments": {},
"products": {},
"scratchorg": {},
"search": {},
"store": {
"subtopics": {
"view": {},
Expand Down
35 changes: 30 additions & 5 deletions src/commands/commerce/products/import.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* Copyright (c) 2022, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand All @@ -8,6 +8,7 @@ import { SfdxCommand } from '@salesforce/command';
import { fs, Messages, Org, SfdxError } from '@salesforce/core';
import chalk from 'chalk';
import { AnyJson } from '@salesforce/ts-types';
import { JsonCollection } from '@salesforce/ts-types/lib/types/json';
import { productsFlags } from '../../../lib/flags/commerce/products.flags';
import { storeFlags } from '../../../lib/flags/commerce/store.flags';
import { addAllowedArgs, filterFlags, modifyArgFlag } from '../../../lib/utils/args/flagsUtils';
Expand All @@ -26,6 +27,8 @@ Messages.importMessagesDirectory(__dirname);
const TOPIC = 'products';
const CMD = `commerce:${TOPIC}:import`;
const msgs = Messages.loadMessages('@salesforce/commerce', TOPIC);
const WEBSTORE_ID = '${WEBSTORE_ID}';
const PRODUCT_IMPORT_API_PATH = `commerce/management/webstores/${WEBSTORE_ID}/product-import`;

export class ProductsImport extends SfdxCommand {
public static readonly requiresUsername = true;
Expand Down Expand Up @@ -81,7 +84,7 @@ export class ProductsImport extends SfdxCommand {
this.ux.startSpinner(msgs.getMessage('import.importingProducts'));
this.ux.setSpinnerStatus(msgs.getMessage('import.uploading'));
try {
let res = shellJsonSfdx<ImportResult>(
const res = shellJsonSfdx<ImportResult>(
`sfdx shane:data:file:upload -f ${
this.flags['products-file-csv'] as string
} -u "${this.org.getUsername()}" --json`
Expand All @@ -96,9 +99,7 @@ export class ProductsImport extends SfdxCommand {
msgs.getMessage('import.importingProductsImportFileIdAndStoreId', [importFileId, storeId])
);
try {
res = shellJsonSfdx(
`sfdx 1commerce:import:products -d "${importFileId}" -w "${storeId}" -u "${this.org.getUsername()}"`
);
await this.importFromUploadedFile(importFileId, storeId);
} catch (e) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
if (e.message.indexOf('UniqueConstraintViolationException') < 0) {
Expand Down Expand Up @@ -276,4 +277,28 @@ export class ProductsImport extends SfdxCommand {
// Return BuyerGroup Name to be used in BuyerGroup Account mapping
return newbuyergroupname;
}

public async importFromUploadedFile(contentVersionId: string, webStoreId: string): Promise<JsonCollection> {
const conn = this.org.getConnection();
const url = `${conn.baseUrl()}/${PRODUCT_IMPORT_API_PATH.replace(WEBSTORE_ID, webStoreId)}`;

this.ux.log(`Starting import for WebStore ID: ${webStoreId} to ${url}`);

return await conn.request({
method: 'POST',
url,
body: `{
"importConfiguration": {
"importSource": {
"contentVersionId": "${contentVersionId}"
}
}
}`,
headers: {
key: 'Content-Type',
type: 'text',
value: 'application/json',
},
});
}
}
Loading

0 comments on commit 07c85a4

Please sign in to comment.