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

Feat/add product sync #45

Merged
merged 2 commits into from
Oct 30, 2023
Merged
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
Binary file modified dump.rdb
Binary file not shown.
2 changes: 1 addition & 1 deletion medusa-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const plugins = [
const { id, title, description, thumbnail, handle } = product;
const prices = {};

product.variants[0].prices.forEach((price) => {
product.variants?.[0]?.prices.forEach((price) => {
prices[price.currency_code] = price.amount;
});

Expand Down
32 changes: 22 additions & 10 deletions src/services/category.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ProductCategory, ProductCategoryService } from "@medusajs/medusa";
import { buildLocationTree, getLastLocationPath, getLocationPath, getLocationPathWithLastID } from "../utils/convertIntoNestedLocations";


class CategoryService extends ProductCategoryService {
constructor(container) {
Expand All @@ -15,17 +15,30 @@ class CategoryService extends ProductCategoryService {
}

async retrieveAllLastLocationsName() {
const retrieveAllLocations = `
SELECT name, id, parent_category_id FROM "product_category" WHERE handle LIKE 'loc:%'
`
const categories = await this.listAndCount({})
const res = await Promise.all(categories[0].map((c) => {
return this.productCategoryRepo_.findDescendantsTree(c)
}))

const childCategories = res.filter(r => !r.category_children?.length && r.handle.startsWith('loc:'));

const categoriesWithParent = await Promise.all(childCategories.map((c) => this.productCategoryRepo_.findAncestorsTree(c)))

const result = await this.activeManager_.query(retrieveAllLocations) as { name: string, id: string, parent_category_id: string }[]

// Convert the location tree to slash-separated strings
return categoriesWithParent.map((category) => {
const list = [];

const nestedLocations = buildLocationTree(result);
const locationStrings: string[] = getLocationPath(nestedLocations)
return locationStrings
const getParent = (pcat: ProductCategory) => {
if (pcat.parent_category) {
list.unshift(pcat.name)
getParent(pcat.parent_category)
}
}

getParent(category);

return list.join(' / ');
})
}


Expand All @@ -43,7 +56,6 @@ class CategoryService extends ProductCategoryService {

const getLocation = async (locationId: string) => {
const location = await this.retrieve(locationId);

if (location.parent_category_id) {
locations.unshift(location)
await getLocation(location.parent_category_id)
Expand Down
1 change: 0 additions & 1 deletion src/services/customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default class CustomerService extends BaseCustomerService {
const customerResult = await this.activeManager_.query(customerByEmailQuery, [email]) as Customer[]

if (!customerResult.length) {
console.log(customerResult);
throw new Error('Customer not found with this email!')
}

Expand Down
Loading