bigcommerce/bigcommerce-api-python

Shipment hasn't field "items"

Opened this issue · 1 comments

How get items of shipment using this lib?
Doc of shipment has point "items" https://developer.bigcommerce.com/api/objects/v2/shipment

order = client.Orders.get(1)
shipment = order.shipments()[0]
# or
shipments = client.OrderShipments.all(1)[0] # id of order

# it returns <function items>
items = shipments.items 

# it returns a list of fields without items
items = shipments.items()

# it returns KeyError: 'items'
shipment['items']

How can I get it using this lib?

Same problem arisen here, i am also unable to get shipment items within order.

In python dict object has standard function, which is items and item function return attributes of dict along with values in the form of list of tuples.
For example:
dict.items**({"key":"val"})** function will return [(u'key', u'val')].

Now while creating object, it discard the attribute items, this is bug and has to fix or has to change its attribute name items to any other attribute.

Resolution to your problem is:
Go to base class in /bigcommerce/resource/base.py and open the file using any editor.
and insert a new line (I.e where i have written changed/newly added)



class Mapping(dict):
    """
    Mapping

    provides '.' access to dictionary keys
    """
    def __init__(self, mapping, *args, **kwargs):
        """
        Create a new mapping. Filters the mapping argument
        to remove any elements that are already methods on the
        object.

        For example, Orders retains its `coupons` method, instead
        of being replaced by the dict describing the coupons endpoint
        """
        filter_args = {k: mapping[k] for k in mapping if k not in dir(self)}
        filter_args['_items'] = mapping['items'] if  mapping.has_key("items") else [] #Changed/Newly Added
        self.__dict__ = self
        dict.__init__(self, filter_args, *args, **kwargs)

    def __str__(self):
        """
        Display as a normal dict, but filter out underscored items first
        """
        return str({k: self.__dict__[k] for k in self.__dict__ if not k.startswith("_")})

    def __repr__(self):
        return "<%s at %s, %s>" % (type(self).__name__, hex(id(self)), str(self))