Skip to content

Commit

Permalink
Merge pull request #45 from curiosta/feat/add-product-sync
Browse files Browse the repository at this point in the history
Feat/add product sync
  • Loading branch information
ShivamJoker authored Oct 30, 2023
2 parents 2935e8e + a76a095 commit 111a256
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
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

0 comments on commit 111a256

Please sign in to comment.