示例#1
0
    def getCustomerFullname(self):
        """
        """
        # Todo: Create an adapter Address Management for IOrder
        customer = self.context.getCustomer()
        am = IAddressManagement(customer)
        address = am.getInvoiceAddress()

        return address.getName()
示例#2
0
    def getCustomerFullname(self):
        """
        """
        # Todo: Create an adapter Address Management for IOrder
        customer = self.context.getCustomer()
        am = IAddressManagement(customer)
        address = am.getInvoiceAddress()

        return address.getName()
示例#3
0
 def getInvoiceAddress(self):
     """Returns invoice address of the current customer.
     """
     cm = ICustomerManagement(self.context)
     customer = cm.getAuthenticatedCustomer()
     
     am = IAddressManagement(customer)
     address = am.getInvoiceAddress()
     
     return addressToDict(address)
示例#4
0
    def getInvoiceAddress(self):
        """Returns invoice address of the current customer.
        """
        cm = ICustomerManagement(self.context)
        customer = cm.getAuthenticatedCustomer()

        am = IAddressManagement(customer)
        address = am.getInvoiceAddress()

        return addressToDict(address)
示例#5
0
    def process(self, order):
        """
        """
        info = dict()

        pc = IPrices(order)

        customer = order.getCustomer()

        am = IAddressManagement(customer)
        invoice_address  = am.getInvoiceAddress()
        shipping_address = am.getShippingAddress()

        info = {
            "cmd" : "_cart",
            "upload" : "1",
            "business" : "*****@*****.**",
            "currency_code" : "EUR",
            "notify_url" : "",
            "return" : "",
            "last_name" : shipping_address.getName(),
            "address1" : shipping_address.address_1,
            "city" : shipping_address.city,
            "state" : shipping_address.country_title(),
            "zip" : shipping_address.zip_code,
            "shipping_1" : order.getShippingPriceNet(),
            "tax_1" : pc.getPriceGross() - pc.getPriceNet()
        }

        im = IItemManagement(order)
        for i, item in enumerate(im.getItems()):
            j = i + 1
            name     = "item_name_%s" % j
            quantity = "quantity_%s" % j
            amount   = "amount_%s" % j

            product = item.getProduct()

            info[name]     = product.Title()
            info[quantity] = str(int(item.getProductQuantity()))
            info[amount]   = str(item.getProductPriceGross())

        # redirect to paypal
        parameters = "&".join(["%s=%s" % (k, v) for (k, v) in info.items()])

        url = PAYPAL_URL + "?" + parameters
        self.context.REQUEST.RESPONSE.redirect(url)

        return PaymentResult(NOT_PAYED)
示例#6
0
    def process(self, order=None):
        """
        """
        info = dict()

        shop = IShopManagement(self.context).getShop()
        notify_url = "%s/paypal?order=%s" % (shop.absolute_url(), order.UID())
        return_url = "%s/thank-you" % shop.absolute_url()

        pc = IPrices(order)
        price_net = "%.2f" % pc.getPriceNet()
        tax = "%.2f" % (pc.getPriceGross() - float(price_net))

        customer = order.getCustomer()
        am = IAddressManagement(customer)
        invoice_address  = am.getInvoiceAddress()
        shipping_address = am.getShippingAddress()

        site_encoding = self.context.plone_utils.getSiteEncoding()

        info = {
            "cmd" : "_xclick",
            "upload" : "1",
            "business" : shop.getPayPalId(),
            "currency_code" : "EUR",
            "notify_url" : notify_url,
            "return" : return_url,
            "first_name" : invoice_address.firstname.encode(site_encoding),
            "last_name" : invoice_address.lastname.encode(site_encoding),
            "address1" : invoice_address.address_1.encode(site_encoding),
            "address2" : "",
            "city" : invoice_address.city.encode(site_encoding),
            "state" : invoice_address.country_title().encode(site_encoding),
            "zip" : invoice_address.zip_code.encode(site_encoding),
            "no_shipping" : "1",
            "item_name" : shop.getShopOwner(),
            "amount" : price_net,
            "tax" : tax,
        }

        # redirect to paypal
        parameters = "&".join(["%s=%s" % (k, v) for (k, v) in info.items()])

        url = PAYPAL_URL + "?" + parameters
        self.context.REQUEST.RESPONSE.redirect(url)

        return PaymentResult(NOT_PAYED)
示例#7
0
    def isComplete(self):
        """Checks weather the customer is complete to checkout.
        
           Customer completeness means the customer is ready to check out:
             1. Invoice address is complete
             2. Shipping address is complete
             3. Selected payment method is complete
             4. There a items in the cart            
        """        
        # Get shop
        shop = IShopManagement(self.context).getShop()
        
        # Get shipping and invoice address
        adressman = IAddressManagement(self.context)
        
        s_addr = adressman.getShippingAddress()
        if s_addr is None: return False
        
        i_addr = adressman.getInvoiceAddress()
        if i_addr is None: return False

        # Get payment method
        payman = IPaymentManagement(self.context)
        paymeth = payman.getSelectedPaymentMethod()

        # Get cart of the customer
        cart = ICartManagement(shop).getCart()

        # If there is no cart, the customer hasn't selected a product, hence
        # he is not complete
        if cart is None:
            return False
            
        im = IItemManagement(cart)
        
        # Check all for completeness
        # if at least one is False customer is not complete, too.        
        for toCheck in s_addr, i_addr, paymeth:
            if ICompleteness(toCheck).isComplete() == False:
                return False
        
        # check items in cart
        if im.hasItems() == False:
            return False

        return True
示例#8
0
    def isComplete(self):
        """Checks weather the customer is complete to checkout.
        
           Customer completeness means the customer is ready to check out:
             1. Invoice address is complete
             2. Shipping address is complete
             3. Selected payment method is complete
             4. There a items in the cart            
        """
        # Get shop
        shop = IShopManagement(self.context).getShop()

        # Get shipping and invoice address
        adressman = IAddressManagement(self.context)

        s_addr = adressman.getShippingAddress()
        if s_addr is None: return False

        i_addr = adressman.getInvoiceAddress()
        if i_addr is None: return False

        # Get payment method
        payman = IPaymentManagement(self.context)
        paymeth = payman.getSelectedPaymentMethod()

        # Get cart of the customer
        cart = ICartManagement(shop).getCart()

        # If there is no cart, the customer hasn't selected a product, hence
        # he is not complete
        if cart is None:
            return False

        im = IItemManagement(cart)

        # Check all for completeness
        # if at least one is False customer is not complete, too.
        for toCheck in s_addr, i_addr, paymeth:
            if ICompleteness(toCheck).isComplete() == False:
                return False

        # check items in cart
        if im.hasItems() == False:
            return False

        return True
示例#9
0
    def getInvoiceAddress(self):
        """
        """
        # Todo: Create an adapter Address Management for IOrder
        customer = self.context.getCustomer()
        am = IAddressManagement(customer)
        address = am.getInvoiceAddress()

        return {
            "name": address.getName(),
            "company_name": address.company_name,
            "address1": address.address_1,
            "zipcode": address.zip_code,
            "city": address.city,
            "country": address.country_title(),
            "phone": address.phone
        }
示例#10
0
    def getInvoiceAddress(self):
        """
        """
        # Todo: Create an adapter Address Management for IOrder
        customer = self.context.getCustomer()
        am = IAddressManagement(customer)
        address = am.getInvoiceAddress()

        return {
            "name" : address.getName(),
            "company_name" : address.company_name,
            "address1" : address.address_1,
            "zipcode" : address.zip_code,
            "city": address.city,
            "country" : address.country_title(),
            "phone" : address.phone
        }
示例#11
0
    def getOrders(self):
        """
        """
        tool = getToolByName(self.context, 'translation_service')

        shop = IShopManagement(self.context).getShop()

        wftool = getToolByName(self.context, "portal_workflow")
        filter = self.request.get("filter", "all")
        if filter == "all": filter = None

        sorting = self.request.get("sorting", "created")
        order = self.request.get("order", "descending")

        orders = []
        om = IOrderManagement(shop)

        for order in om.getOrders(filter, sorting, order):

            # get fullname
            fullname = "There is no customer."
            customer = order.getCustomer()
            if customer is not None:
                am = IAddressManagement(customer)
                address = am.getInvoiceAddress()
                if address is not None:
                    fullname = address.getName(reverse=True)

            # created
            created = tool.ulocalized_time(order.created(), long_format=True)

            orders.append({
                "id":
                order.getId(),
                "url":
                order.absolute_url(),
                "created":
                created,
                "customer_name":
                fullname,
                "review_state":
                wftool.getInfoFor(order, "review_state")
            })

        return orders
示例#12
0
    def getOrders(self):
        """
        """
        ttool = getToolByName(self.context, 'translation_service')
        wftool = getToolByName(self.context, "portal_workflow")

        customer = self._getCustomer()
        if customer is None:
            return []

        om = IOrderManagement(self._getShop())

        orders = []
        for order in om.getOrdersForCustomer(customer.getId()):

            # get fullname
            fullname = "There is no customer."
            customer = order.getCustomer()
            if customer is not None:
                am = IAddressManagement(customer)
                address = am.getInvoiceAddress()
                if address is not None:
                    fullname = address.getName(reverse=True)

            # created
            created = ttool.ulocalized_time(order.created(), long_format=True)

            orders.append({
                "id":
                order.getId(),
                "url":
                order.absolute_url(),
                "created":
                created,
                "customer_name":
                fullname,
                "review_state":
                wftool.getInfoFor(order, "review_state")
            })

        return orders
示例#13
0
    def getOrders(self):
        """
        """
        ttool = getToolByName(self.context, 'translation_service')
        wftool = getToolByName(self.context, "portal_workflow")

        customer = self._getCustomer()
        if customer is  None:
            return []

        om = IOrderManagement(self._getShop())

        orders = []
        for order in om.getOrdersForCustomer(customer.getId()):

            # get fullname
            fullname = "There is no customer."
            customer = order.getCustomer()
            if customer is not None:
                am = IAddressManagement(customer)
                address = am.getInvoiceAddress()
                if address is not None:
                    fullname = address.getName(reverse=True)

            # created
            created = ttool.ulocalized_time(order.created(), long_format=True)

            orders.append({
                "id"            : order.getId(),
                "url"           : order.absolute_url(),
                "created"       : created,
                "customer_name" : fullname,
                "review_state"  : wftool.getInfoFor(order, "review_state")
            })

        return orders
示例#14
0
 def testGetInvoiceAddress(self):
     """
     """
     am = IAddressManagement(self.customer)
     self.assertEqual(am.getInvoiceAddress().getId(), "address_1")
 def testGetInvoiceAddress(self):
     """
     """
     am = IAddressManagement(self.customer)
     self.assertEqual(am.getInvoiceAddress().getId(), "address_1")