axxtn
axxtn

Reputation: 11

Shopify Automated Checkout Bot

Issue Description:

Hello,

I'm currently working on a Python project related to a automated checkout bot for Shopify, and I've encountered an issue that I'm struggling to resolve. I would greatly appreciate your guidance on this matter.

The project involves scraping product data from a Shopify website, particularly from the .json files associated with the products.

Specifically, the script reports that "Size L" is not available for certain products, even though it should be.

To test the bot I am using following site: https://nude-project.com/collections/playboy-x-nude-project.json to extract the data. Heres the output it gives me: Size not available: L Selected size (L) not found among product variants.

I anticipate that the bot should correctly retrieve product information from the JSON URL, including the accurate availability of selected sizes.

Any comments, suggestions, or insights you can offer to help improve my project would be greatly appreciated. If you need any specific code snippets just tell me and I will go share them with you.

This is the some code that may help:

   def get_product_variants(updated_link):
    endpoint = f'{updated_link}'
    try:
        response = requests.get(endpoint)
        response.raise_for_status()
        product_data = response.json()
        variants = product_data.get('variants', [])
        variant_objects = []

        for variant in variants:
            vid = variant.get('id')
            title = variant.get('title')
            stock = variant.get('inventory_quantity', None)
            variant_objects.append(Variant(vid, title, stock))

        return variant_objects
    except requests.exceptions.HTTPError as e:
        print(f"Failed to get variants: {e}")
        return []

   def compare_variants(variant_list, selected_size):
    size_synonyms = {
        "xs": ["extra small", "x-small"],
        "s": ["small"],
        "m": ["medium"],
        "l": ["large"],
        "xl": ["extra large", "x-large"],
    }
    
    selected_size = selected_size.lower()
    
    for variant in variant_list:
        title = variant.title.lower()
        
        print(f"Variant Title: {title}")
        
        if selected_size in title:
            return variant
        
        for size, synonyms in size_synonyms.items():
            if selected_size in synonyms and size in title:
                return variant
    
    return None

I was trying to extract the variants(Sizes) from a product url of a shopify site that includes the .json ending.

Heres an example: https://nude-project.com/collections/playboy-x-nude-project/products/pool-boxer.json

The error I am getting is, that the item is not available in size L(selected size) but I have checked and its available.

I must have done something wrong when extracting the variants, but I dont know what to change.

I was expecting the programm to extract all of the variants for a specific product and use this to create the add_to_cart function afterwards.

Thanks for any help

Upvotes: 1

Views: 472

Answers (0)

Related Questions