cancel
Showing results for 
Search instead for 
Did you mean: 

How to export Hybris cart and cart entries in one go

0 Kudos

Below export script is working.

"#% impex.setTargetFile( ""cartentry.csv"" );"

insert_update cartentry;order(code);order(creationtime);order(modifiedtime); order(user(uid))[alias=siteId];order(user(name))[alias=name];order(deliveryAddress(email))[alias=email] ;order(deliveryAddress(phone1))[alias=phone];

"#% impex.exportItemsFlexibleSearch( ""Select {pk} from {cartentry as e join cart as o on {e.order}={o.pk} join Customer as c on {c.pk} = {o.user} join Address as a on {o.deliveryaddress} = {a.pk} join CMSSite as s on {s.pk}={o.site} join TmaProductOffering as p on {e.product}={p.pk} JOIN CatalogVersion as cat on {p.catalogVersion}={cat.pk} JOIN EnumerationValue as en on {en.pk}={p.poType}} where {cat.version}='Online' AND ({a.email} is NOT NULL OR {a.phone1} is NOT NULL) AND {s.uid} = 'sunriseUpc' AND {e.bpo} is NULL AND {o.creationtime} >= '2023-02-01 00:00:00' ORDER BY {o.creationtime} "" );"

However below one is not working.

"#% impex.setTargetFile( ""cartentry.csv"" );"

insert_update cartentry;order(code);order(creationtime);order(modifiedtime); order(user(uid))[alias=siteId];order(user(name))[alias=name];order(deliveryAddress(email))[alias=email] ;order(deliveryAddress(phone1))[alias=phone];product(potype(code,itemtype(code)))[alias=potype];

"#% impex.exportItemsFlexibleSearch( ""Select {pk} from {cartentry as e join cart as o on {e.order}={o.pk} join Customer as c on {c.pk} = {o.user} join Address as a on {o.deliveryaddress} = {a.pk} join CMSSite as s on {s.pk}={o.site} join TmaProductOffering as p on {e.product}={p.pk} JOIN CatalogVersion as cat on {p.catalogVersion}={cat.pk} JOIN EnumerationValue as en on {en.pk}={p.poType}} where {cat.version}='Online' AND ({a.email} is NOT NULL OR {a.phone1} is NOT NULL) AND {s.uid} = 'sunriseUpc' AND {e.bpo} is NULL AND {o.creationtime} >= '2023-02-01 00:00:00' ORDER BY {o.creationtime} "" );"

<enumtype code="xyzPoType">
<value code="M_ORDER"/>
<value code="H_ORDER"/> </enumtype>
<itemtype code="TmaProductOffering" autocreate="false" generate="false">
<attributes>
<attribute qualifier="poType" type="xyzPoType">
<persistence type="property"/>
</attribute>
</attributes>

</itemtype>

While exporting getting below error.

ERROR line 4 at main script: unknown attributes [Product.poType] - cannot resolve item reference

Something wrong with the headers and not with query because below flexiquery is working.select {o.code} as cartId, {en.code} as poType, {c.name} as name, {c.uid} as siteId, {a.email} as email, {a.phone1} as phone, {o.creationtime} as creationtime, {o.modifiedtime} as modifiedtime from {Cart as o join Customer as c on {c.pk} = {o.user} join Address as a on {o.deliveryaddress} = {a.pk} join cartentry as e on {e.order}={o.pk} join CMSSite as s on {s.pk}={o.site} join TmaProductOffering as p on {e.product}={p.pk} JOIN CatalogVersion as cat on {p.catalogVersion}={cat.pk} JOIN EnumerationValue as en on {en.pk}={p.poType} } where {cat.version}='Online' AND ({a.email} is NOT NULL OR {a.phone1} is NOT NULL) AND {s.uid} = 'abc' AND {e.bpo} is NULL AND {o.creationtime} >= '2023-02-01 00:00:00'

Accepted Solutions (0)

Answers (2)

Answers (2)

adiputera
Active Participant

As PoType is from TmaProductOffering, and Product in CartEntry is Product type, you need to tell hybris to get it from TmaProductOffering, or to "cast" it, I post a question before about it, you can see it from this link.

Anyway, for you question, your impex should be:

insert_update cartentry;order(code);order(creationtime);order(modifiedtime); order(user(uid))[alias=siteId];order(user(name))[alias=name];order(deliveryAddress(email))[alias=email] ;order(deliveryAddress(phone1))[alias=phone];product(TmaProductOffering.potype(code,itemtype(code)))[alias=potype];
0 Kudos

Thank you. Working as expected.

adiputera
Active Participant
0 Kudos

daniel_robinson_elangovan

You're welcome, kindly upvote and accept the answer if it's already working.

romitchhabra
Participant
0 Kudos

Hi Daniel,

Your header is trying to get poType from Product Type because of "product(potype(code,itemtype(code)))[alias=potype]".

It seems that potype is not there in product but it is in TmaProductOffering, hence you are getting the error. Note that product attribute in CartEntry is of type Product & not of type TmaProductOffering.

Hope this helps you in fixing the header.

Regards,

Romit Chhabra

0 Kudos

Thanks for your feedback.