Replies: 1 comment
-
Hey @lpcs007 So here is how I would do this (I think) based on what you have provided and thinking off the top of my head. I would extract all the different product options and their values from the variants, something like: $options = [];
foreach($response['ae_item_sku_info_dtos']['ae_item_sku_info_d_t_o'] as $item) {
$options = [
...$options,
$item['ae_sku_property_dtos']['ae_sku_property_d_t_o']
];
} I would then dedupe them $options = collect($options)->unique(
fn ($option) => $option['sku_property_id'].$option['sku_property_name'].$option['sku_property_value']
)->values(); Then I would probably create a separate class to import just those options into Lunar and return all option values available in the database. $optionValues = ImportProductOptionValues::run($options); Once you have the available options and their values you can then loop through your product variants and map them to their Lunar values in the database and use the I hope that helps and might not be exactly correct as I don't have anything to run my thinking against, but if you also separate the different parts into different classes which perform one action such as Another thing I usually do with these types of importing situations is wrap parts in database transactions so you can roll back if anything goes wrong and you minimise bad data from being committed. |
Beta Was this translation helpful? Give feedback.
-
I am building my store for dropshipping and I already have the AliExpress API enabled to fetch product data and register it in LunarPHP. However, their SDK is poorly developed and seems outdated. So I rewrote their SDK to work with Laravel, and so far, the queries are working fine. But I’ve encountered a problem: their API response is not very well organized, and I'm struggling to import data when the product has variants (sizes, colors, types, etc.).
Currently, I can import all the data, including images. However, when the image is in the product description, it imports the URL from the AliExpress CDN. But that's not a big problem and isn’t too hard to fix.
I won’t paste the entire API response here as it’s quite long, but I'll include the part where the variants are returned:
So far, I’ve figured out that when
sku_property_id = 5
, it refers to Size, and when it issku_property_id = 14
, it refers to Color. But in some products, the array insideae_sku_property_d_t_o
doesn't just return the variations but also information like whether the product is from the USA, which is not considered a variant and should not be imported.With this information, I wrote the following code:
As you can see, I didn't include the foreach loop because I’m still having trouble organizing the variations. So, with this code, I'm importing only the first variation.
My questions are:
Beta Was this translation helpful? Give feedback.
All reactions