def createTransientOrder(self):
        order = Order()
        shopping_cart = component.getUtility(
            interfaces.IShoppingCartUtility
        ).get(self.context)
        formSchemas = component.getUtility(interfaces.IFormSchemas)

        # shopping cart is attached to the session, but we want to switch the
        # storage to the persistent zodb, we pickle to get a clean copy to
        # store.
        adapters = self.wizard.data_manager.adapters

        order.shopping_cart = loads(dumps(shopping_cart))

        for section in (
            'contact_information',
            'billing_address',
            'shipping_address'):
            interface = formSchemas.getInterface(section)
            bag = formSchemas.getBagClass(
                section).frominstance(adapters[interface])
            setattr(order, section, bag)

        order.order_id = self.wizard.data_manager.get('order_id')
        order.user_id = getSecurityManager().getUser().getId()

        return order
Ejemplo n.º 2
0
def create_test_order(context, order_id='1111111111'):
    """
    creates an order with a line item using a new cart.
    """
    item = LineItem()
    item.item_id = order_id
    item.name = "Jug of beer"
    item.cost = 5.00
    item.quantity = 5
    item.description = "Really nice beer"

    cart_util = getUtility(IShoppingCartUtility)
    cart = cart_util.get(context, create=True)
    cart[item.item_id] = item

    order = Order()
    order.order_id = order_id
    order.shopping_cart = cart
    order.processor_id = 'PXPay Processor'
    order.contact_information = ContactInformation()
    return order