コード例 #1
0
ファイル: address_forms.py プロジェクト: Easyshop/Easyshop
 def createAndAdd(self, data):
     """
     """
     am = IAddressManagement(self.context)
     am.addAddress(data)
     
     self.redirectToNextURL()
コード例 #2
0
    def getShippingAddresses(self):
        """Returns all addresses with the currently selected invoice address
        checked.
        """
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        am = IAddressManagement(customer)

        found_selected_address = False
        result = []
        line = []

        for index, address in enumerate(am.getAddresses()):

            checked = False
            if safe_unicode(
                    address.getId()) == customer.selected_shipping_address:
                checked = "checked"
                found_selected_address = True

            address_as_dict = self._getAddressAsDict(address)
            address_as_dict["checked"] = checked

            line.append(address_as_dict)

            if (index + 1) % 3 == 0:
                result.append(line)
                line = []

        result.append(line)

        if len(result) > 0 and found_selected_address == False:
            result[0][0]["checked"] = True

        return result
コード例 #3
0
    def createAndAdd(self, data):
        """
        """
        am = IAddressManagement(self.context)
        am.addAddress(data)

        self.redirectToNextURL()
コード例 #4
0
    def getAddresses(self):
        """
        """
        customer = self._getCustomer()
        if customer is None:
            return None

        goto  = self.context.absolute_url()
        goto += "?letter=%s" % self.request.get("letter")
        goto += "&id=%s" % customer.id
        goto  = urllib.quote(goto)

        am = IAddressManagement(customer)

        addresses = []
        for address in am.getAddresses():

            # create name
            name = address.firstname + " " + address.lastname

            addresses.append({
                "name"     : name,
                "address1" : address.address_1,
                "phone"    : address.phone,
                "url"      : address.absolute_url() + "/@@edit?goto=" + goto
            })

        return addresses
コード例 #5
0
ファイル: address_select.py プロジェクト: Easyshop/Easyshop
    def getShippingAddresses(self):
        """Returns all addresses with the currently selected invoice address
        checked.
        """
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        am = IAddressManagement(customer)

        found_selected_address = False
        result = []
        line = []

        for index, address in enumerate(am.getAddresses()):

            checked = False
            if safe_unicode(address.getId()) == customer.selected_shipping_address:
                checked = "checked"
                found_selected_address = True

            address_as_dict = self._getAddressAsDict(address)
            address_as_dict["checked"] = checked

            line.append(address_as_dict)

            if (index + 1) % 3 == 0:
                result.append(line)
                line = []

        result.append(line)

        if len(result) > 0 and found_selected_address == False:
            result[0][0]["checked"] = True

        return result
コード例 #6
0
ファイル: customer.py プロジェクト: Easyshop/Easyshop
    def SearchableText(self):
        """
        """
        text = []

        text.append(self.firstname)
        text.append(self.lastname)
        text.append(self.email)

        am = IAddressManagement(self)
        for address in am.getAddresses():
            if address.firstname:
                text.append(address.firstname)
            if address.lastname:
                text.append(address.lastname)
            if address.address_1:
                text.append(address.address_1)
            if address.zip_code:
                text.append(address.zip_code)
            if address.city:
                text.append(address.city)
            if address.country_title():
                text.append(address.country_title())

        return " ".join(text)
コード例 #7
0
ファイル: customer.py プロジェクト: viona/Easyshop
    def SearchableText(self):
        """
        """
        text = []

        text.append(self.firstname)
        text.append(self.lastname)
        text.append(self.email)

        am = IAddressManagement(self)
        for address in am.getAddresses():
            if address.firstname:
                text.append(address.firstname)
            if address.lastname:
                text.append(address.lastname)
            if address.address_1:
                text.append(address.address_1)
            if address.zip_code:
                text.append(address.zip_code)
            if address.city:
                text.append(address.city)
            if address.country_title():
                text.append(address.country_title())

        return " ".join(text)
コード例 #8
0
    def getAddresses(self):
        """
        """
        customer = self._getCustomer()
        if customer is None:
            return None

        goto = self.context.absolute_url()
        goto += "?letter=%s" % self.request.get("letter")
        goto += "&id=%s" % customer.id
        goto = urllib.quote(goto)

        am = IAddressManagement(customer)

        addresses = []
        for address in am.getAddresses():

            # create name
            name = address.firstname + " " + address.lastname

            addresses.append({
                "name":
                name,
                "address1":
                address.address_1,
                "phone":
                address.phone,
                "url":
                address.absolute_url() + "/@@edit?goto=" + goto
            })

        return addresses
コード例 #9
0
    def getAddressInfo(self):
        """
        """
        id = self.request.get("id")
        cm = ICustomerManagement(self.context)
        customer = cm.getAuthenticatedCustomer()
        
        am = IAddressManagement(customer)
        address = am.getAddress(id)
        
        result = {}
        result["id"] = id
         
        if self.request.get("firstname", "") != "":
            result["firstname"] = self.request.get("firstname")
        else:
            result["firstname"] = address.getFirstname()

        if self.request.get("lastname", "") != "":
            result["lastname"] = self.request.get("lastname")
        else:
            result["lastname"] = address.getLastname()

        if self.request.get("companyname", "") != "":
            result["companyname"] = self.request.get("companyname")
        else:
            result["companyname"] = address.getCompanyName()

        if self.request.get("address1", "") != "":
            result["address1"] = self.request.get("address1")
        else:
            result["address1"] = address.getAddress1()

        if self.request.get("address2", "") != "":
            result["address2"] = self.request.get("address2")
        else:
            result["address2"] = address.getAddress2()

        if self.request.get("zipcode", "") != "":
            result["zipcode"] = self.request.get("zipcode")
        else:
            result["zipcode"] = address.getZipCode()

        if self.request.get("city", "") != "":
            result["city"] = self.request.get("city")
        else:
            result["city"] = address.getCity()

        if self.request.get("country", "") != "":
            result["country"] = self.request.get("country")
        else:
            result["country"] = address.getCountry()

        if self.request.get("phone", "") != "":
            result["phone"] = self.request.get("phone")
        else:
            result["phone"] = address.getPhone()
            
        return result
コード例 #10
0
ファイル: thank_you.py プロジェクト: ned14/Easyshop
    def getLatestOrder(self):
        """Returns the last order id of authenticated customer
        """
        om = IOrderManagement(self.context)
        orders = om.getOrdersForAuthenticatedCustomer()
        orders.sort(lambda a, b: cmp(b.created(), a.created()))

        order = orders[0]

        # Address
        customer = order.getCustomer()
        address = IAddressManagement(customer).getInvoiceAddress()

        prices = IPrices(order)

        transaction = {
            "order_id": order.getId(),
            "affiliation": "",
            "total": prices.getPriceForCustomer(),
            "tax": (prices.getPriceForCustomer() - prices.getPriceNet()),
            "shipping": order.getShippingPriceGross(),
            "city": address.city,
            "state": "",
            "country": address.country_title(),
        }

        items = []
        for item in IItemManagement(order).getItems():

            # Product
            product = item.getProduct()

            # Category
            try:
                category = product.getCategories()[0]
                category_title = category.Title()
            except IndexError:
                category_title = u""

            items.append(
                {
                    "order_id": order.getId(),
                    "sku": product.getArticleId(),
                    "productname": product.Title(),
                    "category": category_title,
                    "price": item.getProductPriceGross(),
                    "quantity": item.getProductQuantity(),
                }
            )

        result = {
            "id": order.getId(),
            "url": order.absolute_url(),
            "google_transaction": transaction,
            "google_items": items,
        }

        return result
コード例 #11
0
ファイル: order_view.py プロジェクト: Easyshop/Easyshop
    def getEmail(self):
        """
        """
        # Todo: Create an adapter Address Management for IOrder
        customer = self.context.getCustomer()
        am = IAddressManagement(customer)
        address = am.getShippingAddress()

        return address.email
コード例 #12
0
ファイル: order_view.py プロジェクト: viona/Easyshop
    def getEmail(self):
        """
        """
        # Todo: Create an adapter Address Management for IOrder
        customer = self.context.getCustomer()
        am = IAddressManagement(customer)
        address = am.getShippingAddress()

        return address.email
コード例 #13
0
ファイル: order_view.py プロジェクト: Easyshop/Easyshop
    def getCustomerFullname(self):
        """
        """
        # Todo: Create an adapter Address Management for IOrder
        customer = self.context.getCustomer()
        am = IAddressManagement(customer)
        address = am.getInvoiceAddress()

        return address.getName()
コード例 #14
0
ファイル: order_view.py プロジェクト: viona/Easyshop
    def getCustomerFullname(self):
        """
        """
        # Todo: Create an adapter Address Management for IOrder
        customer = self.context.getCustomer()
        am = IAddressManagement(customer)
        address = am.getInvoiceAddress()

        return address.getName()
コード例 #15
0
    def getLatestOrder(self):
        """Returns the last order id of authenticated customer
        """
        om = IOrderManagement(self.context)
        orders = om.getOrdersForAuthenticatedCustomer()
        orders.sort(lambda a, b: cmp(b.created(), a.created()))

        order = orders[0]

        # Address
        customer = order.getCustomer()
        address = IAddressManagement(customer).getInvoiceAddress()

        prices = IPrices(order)

        transaction = {
            "order_id": order.getId(),
            "affiliation": "",
            "total": prices.getPriceForCustomer(),
            "tax": (prices.getPriceForCustomer() - prices.getPriceNet()),
            "shipping": order.getShippingPriceGross(),
            "city": address.city,
            "state": "",
            "country": address.country_title(),
        }

        items = []
        for item in IItemManagement(order).getItems():

            # Product
            product = item.getProduct()

            # Category
            try:
                category = product.getCategories()[0]
                category_title = category.Title()
            except IndexError:
                category_title = u""

            items.append({
                "order_id": order.getId(),
                "sku": product.getArticleId(),
                "productname": product.Title(),
                "category": category_title,
                "price": item.getProductPriceGross(),
                "quantity": item.getProductQuantity()
            })

        result = {
            "id": order.getId(),
            "url": order.absolute_url(),
            "google_transaction": transaction,
            "google_items": items,
        }

        return result
コード例 #16
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)
コード例 #17
0
ファイル: order_preview.py プロジェクト: Easyshop/Easyshop
 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)
コード例 #18
0
ファイル: customer.py プロジェクト: Easyshop/Easyshop
    def _getAddressesAsDL(self):
        """Returns all addresses as DisplayList.
        """
        dl = DisplayList()

        am = IAddressManagement(self)
        for address in am.getAddresses():
            dl.add(address.getId(), address.getName() + " - " + address.getAddress1())

        return dl
コード例 #19
0
ファイル: order_preview.py プロジェクト: Easyshop/Easyshop
    def getShippingAddress(self):
        """
        """
        cm = ICustomerManagement(self.context)
        customer = cm.getAuthenticatedCustomer()
        
        am = IAddressManagement(customer)
        address = am.getShippingAddress()

        return addressToDict(address)
コード例 #20
0
    def getShippingAddress(self):
        """
        """
        cm = ICustomerManagement(self.context)
        customer = cm.getAuthenticatedCustomer()

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

        return addressToDict(address)
コード例 #21
0
ファイル: customer.py プロジェクト: viona/Easyshop
    def _getAddressesAsDL(self):
        """Returns all addresses as DisplayList.
        """
        dl = DisplayList()

        am = IAddressManagement(self)
        for address in am.getAddresses():
            dl.add(address.getId(),
                   address.getName() + " - " + address.getAddress1())

        return dl
コード例 #22
0
 def _editedAddress(self):
     """
     """
     if self.context.REQUEST.get("also_invoice_address", "yes") == "yes":
         url = self.context.absolute_url() + "/checkout-shipping"
     else:
         customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
         invoice_address = IAddressManagement(customer).getInvoiceAddress()
         if invoice_address is None:
             url = self.context.absolute_url() + "/checkout-add-address?address_type=invoice"
         else:
             url = invoice_address.absolute_url() + "/checkout-edit-address"
             
     return url
コード例 #23
0
ファイル: payment_processing.py プロジェクト: viona/Easyshop
    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)
コード例 #24
0
    def testAddAddress(self):
        """
        """
        am = IAddressManagement(self.customer)
        id = am.addAddress({
            "firstname": u"John",
            "lastname": u"Doe",
            "address_1": u"Doe Str. 1",
            "zip_code": u"4711",
            "city": u"Doe City",
            "country": u"Germany"
        })

        ids = [a.getId() for a in am.getAddresses()]
        self.assertEqual(ids, ["address_1", "address_2", "address_3", id])
コード例 #25
0
 def testAddAddress(self):
     """
     """
     am = IAddressManagement(self.customer)
     id = am.addAddress({
         "firstname" : u"John",
         "lastname" : u"Doe",
         "address_1" : u"Doe Str. 1",            
         "zip_code" : u"4711",
         "city" : u"Doe City",
         "country" : u"Germany"
     })
             
     ids = [a.getId() for a in am.getAddresses()]        
     self.assertEqual(ids, ["address_1", "address_2", "address_3", id])
コード例 #26
0
 def deleteAddress(self):
     """
     """
     # delete address
     toDeleteAddressId = self.context.request.get("id")
     am = IAddressManagement(self.context)
     am.deleteAddress(toDeleteAddressId)
     
     # add message
     putils = getToolByName(self.context, "plone_utils")
     putils.addPortalMessage(_("The address has been deleted."))
                                     
     # redirect to addressbook
     url = "%s/manage-addressbook" % self.context.absolute_url()
     self.context.request.response.redirect(url)
コード例 #27
0
    def testDeleteAddress(self):
        """
        """
        am = IAddressManagement(self.customer)

        am.deleteAddress("address_1")
        ids = [a.getId() for a in am.getAddresses()]        
        self.assertEqual(ids, ["address_2", "address_3"])

        am.deleteAddress("address_2")
        ids = [a.getId() for a in am.getAddresses()]        
        self.assertEqual(ids, ["address_3"])

        am.deleteAddress("address_3")
        ids = [a.getId() for a in am.getAddresses()]
        self.assertEqual(ids, [])
コード例 #28
0
 def deleteAddress(self):
     """
     """
     # delete address
     toDeleteAddressId = self.context.request.get("id")
     am = IAddressManagement(self.context)
     am.deleteAddress(toDeleteAddressId)
     
     # add message
     putils = getToolByName(self.context, "plone_utils")
     putils.addPortalMessage(_("The address has been deleted."))
                                     
     # redirect to addressbook
     url = "%s/manage-addressbook" % self.context.absolute_url()
     self.context.request.response.redirect(url)
         
コード例 #29
0
    def _editedAddress(self):
        """
        """
        if self.context.REQUEST.get("also_invoice_address", "yes") == "yes":
            url = self.context.absolute_url() + "/checkout-shipping"
        else:
            customer = ICustomerManagement(
                self.context).getAuthenticatedCustomer()
            invoice_address = IAddressManagement(customer).getInvoiceAddress()
            if invoice_address is None:
                url = self.context.absolute_url(
                ) + "/checkout-add-address?address_type=invoice"
            else:
                url = invoice_address.absolute_url() + "/checkout-edit-address"

        return url
コード例 #30
0
ファイル: payment_processing.py プロジェクト: viona/Easyshop
    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)
コード例 #31
0
ファイル: order_view.py プロジェクト: Easyshop/Easyshop
    def getShippingAddress(self):
        """
        """
        # Todo: Create an adapter Address Management for IOrder
        customer = self.context.getCustomer()
        am = IAddressManagement(customer)
        address = am.getShippingAddress()

        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
        }
コード例 #32
0
ファイル: order_view.py プロジェクト: viona/Easyshop
    def getShippingAddress(self):
        """
        """
        # Todo: Create an adapter Address Management for IOrder
        customer = self.context.getCustomer()
        am = IAddressManagement(customer)
        address = am.getShippingAddress()

        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
        }
コード例 #33
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
コード例 #34
0
 def _gotoAddresses(self):
     """
     """
     customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
     shipping_address = IAddressManagement(customer).getShippingAddress()
     
     mtool = getToolByName(self.context, "portal_membership")
     if mtool.isAnonymousUser():
         if shipping_address is None:
             return self.context.absolute_url() + "/checkout-add-address"
         else:
             return shipping_address.absolute_url() + "/checkout-edit-address"
     else:    
         if shipping_address is None:
             return self.context.absolute_url() + "/checkout-add-address"
         else:
             return self.context.absolute_url() + "/checkout-select-addresses"
コード例 #35
0
ファイル: completeness.py プロジェクト: Easyshop/Easyshop
    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
コード例 #36
0
ファイル: customers_container.py プロジェクト: viona/Easyshop
    def getAddresses(self):
        """
        """
        customer = self._getCustomer()
        if customer is None:
            return None

        goto = self.context.absolute_url()
        goto += "?letter=%s" % self.request.get("letter")
        goto += "&uid=%s" % customer.UID()
        goto = urllib.quote(goto)

        am = IAddressManagement(customer)

        addresses = []
        for address in am.getAddresses():

            # create name
            name = address.getFirstname() + " " + address.getLastname()

            # create address 1
            address1 = address.getAddress1()
            if address.getAddress2():
                address1 += " / "
                address1 += address.getAddress2()

            # create address 2
            address2 = address.getZipCode()  + " " + \
                       address.getCity()     + " - " + \
                       address.getCountry()

            addresses.append({
                "name":
                name,
                "address1":
                address1,
                "address2":
                address2,
                "phone":
                address.getPhone(),
                "url":
                address.absolute_url() + "/@@edit?goto=" + goto
            })

        return addresses
コード例 #37
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
コード例 #38
0
    def getMailInfo(self):
        """
        """
        cm = ICustomerManagement(self.context)
        customer = cm.getAuthenticatedCustomer()
        am = IAddressManagement(customer)
        shipping_address = am.getShippingAddress()

        mtool = getToolByName(self.context, "portal_membership")        
        member = mtool.getAuthenticatedMember()
        
        name  = shipping_address.getFirstname() + " "
        name += shipping_address.getLastname()
                
        return {
            "email" : member.getProperty("email"),
            "name"  : name,
        }
コード例 #39
0
ファイル: customer.py プロジェクト: viona/Easyshop
    def SearchableText(self):
        """
        """
        text = []

        text.append(self.getFirstname())
        text.append(self.getLastname())
        text.append(self.getEmail())

        am = IAddressManagement(self)
        for address in am.getAddresses():
            text.append(address.getFirstname())
            text.append(address.getLastname())
            text.append(address.getAddress1())
            text.append(address.getZipCode())
            text.append(address.getCity())
            text.append(address.getCountry())

        return " ".join(text)
コード例 #40
0
ファイル: customer.py プロジェクト: Easyshop/Easyshop
 def SearchableText(self):
     """
     """
     text = []
     
     text.append(self.getFirstname())
     text.append(self.getLastname())
     text.append(self.getEmail())
     
     am = IAddressManagement(self)
     for address in am.getAddresses():
         text.append(address.getFirstname())
         text.append(address.getLastname())
         text.append(address.getAddress1())
         text.append(address.getZipCode())            
         text.append(address.getCity())
         text.append(address.getCountry())
                     
     return " ".join(text)
コード例 #41
0
    def _gotoAddresses(self):
        """
        """
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        shipping_address = IAddressManagement(customer).getShippingAddress()

        mtool = getToolByName(self.context, "portal_membership")
        if mtool.isAnonymousUser():
            if shipping_address is None:
                return self.context.absolute_url() + "/checkout-add-address"
            else:
                return shipping_address.absolute_url(
                ) + "/checkout-edit-address"
        else:
            if shipping_address is None:
                return self.context.absolute_url() + "/checkout-add-address"
            else:
                return self.context.absolute_url(
                ) + "/checkout-select-addresses"
コード例 #42
0
ファイル: customers_container.py プロジェクト: viona/Easyshop
    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
コード例 #43
0
    def fullname(self):
        """To sort orders on fullname.
        """
        customer = self.getCustomer()
        if customer is None:
            return ""        

        address = IAddressManagement(customer).getInvoiceAddress()
        if address is None:
            return ""
        
        return address.lastname + " " + address.firstname
コード例 #44
0
    def getAddresses(self):
        """
        """
        customer = self._getCustomer()
        if customer is None:
            return None
            
        goto  = self.context.absolute_url()
        goto += "?letter=%s" % self.request.get("letter")
        goto += "&uid=%s" % customer.UID()
        goto  = urllib.quote(goto)
        
        am = IAddressManagement(customer)
        
        addresses = []
        for address in am.getAddresses():
            
            # create name 
            name = address.getFirstname() + " " + address.getLastname()
            
            # create address 1
            address1 = address.getAddress1()
            if address.getAddress2():
                address1 += " / "
                address1 += address.getAddress2()

            # create address 2
            address2 = address.getZipCode()  + " " + \
                       address.getCity()     + " - " + \
                       address.getCountry()
            
            addresses.append({
                "name"     : name,
                "address1" : address1,
                "address2" : address2,                             
                "phone"    : address.getPhone(),
                "url"      : address.absolute_url() + "/@@edit?goto=" + goto
            })

        return addresses
コード例 #45
0
ファイル: address_add.py プロジェクト: Easyshop/Easyshop
    def createAndAdd(self, data):
        """
        """
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        am = IAddressManagement(customer)

        # Set firstname and lastname of the superior customer object.
        if len(customer.firstname) == 0:
            customer.firstname = data.get("firstname")
            customer.lastname = data.get("lastname")

        # Set email of the superior customer object.
        if len(customer.email) == 0:
            customer.email = data.get("email", u"")

        # Reset country selection.
        shop = IShopManagement(self.context).getShop()
        for country in shop.getCountries():
            if queryUtility(IIDNormalizer).normalize(country) == data.get("country"):
                customer.selected_country = country

        am.addAddress(data)
コード例 #46
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
コード例 #47
0
 def testIsComplete(self):
     """
     """        
     c = ICompleteness(self.shop.customers.customer)
     self.assertEqual(c.isComplete(), False)
     
     am = IAddressManagement(self.customer)
     id = am.addAddress({
         "firstname" : u"John",
         "lastname" : u"Doe",
         "address_1" : u"Doe Str. 1",            
         "zip_code" : u"4711",
         "city" : u"Doe City",
         "country" : u"Germany"
     })
     
     self.customer.selected_invoice_address= id        
     self.customer.selected_shipping_address = id
     self.assertEqual(c.isComplete(), False)
     
     view = getMultiAdapter((self.shop.products.product_1, self.shop.products.product_1.REQUEST), name="addToCart")
     view.addToCart()
     
     self.assertEqual(c.isComplete(), True)
コード例 #48
0
    def Description(self):
        """Makes search results more informative.
        """
        customer = self.getCustomer()
        if customer is None:
            return ""

        address = IAddressManagement(customer).getInvoiceAddress()            
        if address is None:
            return ""

        description  = address.firstname + " " 
        description += address.lastname  + " - "
        description += address.address_1 + ", "
        description += address.zip_code  + " "
        description += address.city

        return description
コード例 #49
0
ファイル: country.py プロジェクト: viona/Easyshop
    def isValid(self, product=None):
        """Returns True if the selected country of the current customer is
        within selected countries of the criterion.
        """
        shop = IShopManagement(self.context).getShop()
        customer = ICustomerManagement(shop).getAuthenticatedCustomer()
        shipping_address = IAddressManagement(customer).getShippingAddress()

        if shipping_address is not None:
            country = shipping_address.country
        else:
            country = customer.selected_country

        # Need to convert country into an id
        country = safe_unicode(country)
        country = queryUtility(IIDNormalizer).normalize(country)

        if country in self.context.getCountries():
            return True
        else:
            return False
コード例 #50
0
ファイル: mailing.py プロジェクト: viona/Easyshop
def mailOrderReceived(order):
    """Sends email to customer that the order has been received.
    """
    shop = IShopManagement(order).getShop()

    # Get TOC
    shop = IShopManagement(order).getShop()
    page = IInformationManagement(shop).getInformationPage(
        "terms-and-conditions")

    # Get sender
    mail_addresses = IMailAddresses(shop)
    sender = mail_addresses.getSender()
    bcc = mail_addresses.getReceivers()

    # Get receiver
    customer = order.getCustomer()
    address = IAddressManagement(customer).getShippingAddress()
    receiver = address.email or customer.email

    if sender and receiver:
        view = getMultiAdapter((order, order.REQUEST),
                               name="mail-order-received")
        text = view()

        # get charset
        props = getToolByName(order, "portal_properties").site_properties
        charset = props.getProperty("default_charset")

        sendMailWithAttachements(
            context=order,
            sender=sender,
            receiver=receiver,
            bcc=bcc,
            subject="Bestellbestätigung %s" % shop.Title(),
            text=text,
            files=[])  # (page.getFile().filename, page.getFile())
コード例 #51
0
 def testGetInvoiceAddress(self):
     """
     """
     am = IAddressManagement(self.customer)
     self.assertEqual(am.getInvoiceAddress().getId(), "address_1")
コード例 #52
0
 def testGetShippingAddress(self):
     """
     """
     am = IAddressManagement(self.customer)
     self.assertEqual(am.getShippingAddress().getId(), "address_2")
コード例 #53
0
ファイル: cart.py プロジェクト: Easyshop/Easyshop
    def _refreshCart(self):
        """
        """            
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        
        cart = ICartManagement(self.context).getCart()
        if cart is None:
            return

        # Collect cart item properties for lookup
        selected_properties = {}
        for key, value in self.context.request.items():
            if key.startswith("property_"):
                property_id, cart_item_id = key.split(":")
                property_id = property_id[42:]

                if selected_properties.has_key(cart_item_id) == False:
                    selected_properties[cart_item_id] = []

                selected_properties[cart_item_id].append({
                    "id" : property_id,
                    "selected_option" : value})
        
        im = IItemManagement(cart)
        
        total_items = 0
        i = 1
        for cart_item in im.getItems():
            ci = "cart_item_%s" % i
            amount = self.context.REQUEST.get(ci)
                        
            try:
                amount = int(amount)
            except ValueError:
                continue
            
            if amount < 0:
                continue
                    
            if amount == 0:
                im.deleteItemByOrd(i-1)
            else:    
                cart_item.setAmount(amount)
            i += 1

            # Set properties
            product = cart_item.getProduct()
            if IProductVariant.providedBy(product):
                product = product.aq_inner.aq_parent
                pvm = IProductVariantsManagement(product)
                
                # We need the properties also as dict to get the selected 
                # variant. Feels somewhat dirty. TODO: Try to unify the data 
                # model for properties.
                properties = {}
                for property in selected_properties[cart_item.getId()]:
                    properties[property["id"]] = property["selected_option"]                    
                    
                variant = pvm.getSelectedVariant(properties)
                cart_item.setProduct(variant)
                
                # TODO: At the moment we have to set the properties of the cart
                # item too. This is used in checkout-order-preview. Think about 
                # to get rid of this because the properties are already available 
                # in the variant.
                cart_item.setProperties(selected_properties[cart_item.getId()])
                
            else:
                if selected_properties.has_key(cart_item.getId()):
                    cart_item.setProperties(selected_properties[cart_item.getId()])
                    
        # Set selected country global and within current selected invoice 
        # address. Why? If a customer delete all addresses the current selected 
        # country is still saved global and can be used to calculate the 
        # shipping price.        
        selected_country = safe_unicode(self.request.get("selected_country"))
        customer.selected_country = selected_country
        #invoice_address = IAddressManagement(customer).getInvoiceAddress()
        #if invoice_address is not None:
        #    invoice_address.country = selected_country
        shipping_address = IAddressManagement(customer).getShippingAddress()
        if shipping_address is not None:
            shipping_address.country = queryUtility(IIDNormalizer).normalize(selected_country)

        shop = IShopManagement(self.context).getShop()
        shipping_methods = IShippingMethodManagement(shop).getShippingMethods(check_validity=True)
        shipping_methods_ids = [sm.getId() for sm in shipping_methods]
        selected_shipping_method = self.request.get("selected_shipping_method")

        # Set selected shipping method
        if selected_shipping_method in shipping_methods_ids:
            customer.selected_shipping_method = \
                safe_unicode(self.request.get("selected_shipping_method"))
        else:
            customer.selected_shipping_method = shipping_methods_ids[0]

        # Set selected payment method type
        customer.selected_payment_method = \
            safe_unicode(self.request.get("selected_payment_method"))
        
        # Set selected VAT registration
        selected_vat_country = safe_unicode(self.request.get("selected_vat_country"))
        selected_vat_number  = safe_unicode(self.request.get("selected_vat_number"))
        if selected_vat_country == "" or selected_vat_country is None or selected_vat_number is None:
            customer.vatreg = None
        elif selected_vat_country == "XX":
            customer.vatreg = selected_vat_country
        else:
            customer.vatreg = selected_vat_country + selected_vat_number
コード例 #54
0
ファイル: addresses.py プロジェクト: Easyshop/Easyshop
 def getAddresses(self):
     """
     """
     am = IAddressManagement(self.context)
     return am.getAddresses()    
コード例 #55
0
    def _refreshCart(self):
        """
        """
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()

        cart = ICartManagement(self.context).getCart()
        if cart is None:
            return

        # Collect cart item properties for lookup
        selected_properties = {}
        for key, value in self.context.request.items():
            if key.startswith("property_"):
                property_id, cart_item_id = key.split(":")
                property_id = property_id[42:]

                if selected_properties.has_key(cart_item_id) == False:
                    selected_properties[cart_item_id] = []

                selected_properties[cart_item_id].append({
                    "id":
                    property_id,
                    "selected_option":
                    value
                })

        im = IItemManagement(cart)

        total_items = 0
        i = 1
        for cart_item in im.getItems():
            ci = "cart_item_%s" % i
            amount = self.context.REQUEST.get(ci)

            try:
                amount = int(amount)
            except ValueError:
                continue

            if amount < 0:
                continue

            if amount == 0:
                im.deleteItemByOrd(i - 1)
            else:
                cart_item.setAmount(amount)
            i += 1

            # Set properties
            product = cart_item.getProduct()
            if IProductVariant.providedBy(product):
                product = product.aq_inner.aq_parent
                pvm = IProductVariantsManagement(product)

                # We need the properties also as dict to get the selected
                # variant. Feels somewhat dirty. TODO: Try to unify the data
                # model for properties.
                properties = {}
                for property in selected_properties[cart_item.getId()]:
                    properties[property["id"]] = property["selected_option"]

                variant = pvm.getSelectedVariant(properties)
                cart_item.setProduct(variant)

                # TODO: At the moment we have to set the properties of the cart
                # item too. This is used in checkout-order-preview. Think about
                # to get rid of this because the properties are already available
                # in the variant.
                cart_item.setProperties(selected_properties[cart_item.getId()])

            else:
                if selected_properties.has_key(cart_item.getId()):
                    cart_item.setProperties(
                        selected_properties[cart_item.getId()])

        # Set selected country global and within current selected invoice
        # address. Why? If a customer delete all addresses the current selected
        # country is still saved global and can be used to calculate the
        # shipping price.
        selected_country = safe_unicode(self.request.get("selected_country"))
        customer.selected_country = selected_country
        #invoice_address = IAddressManagement(customer).getInvoiceAddress()
        #if invoice_address is not None:
        #    invoice_address.country = selected_country
        shipping_address = IAddressManagement(customer).getShippingAddress()
        if shipping_address is not None:
            shipping_address.country = queryUtility(IIDNormalizer).normalize(
                selected_country)

        shop = IShopManagement(self.context).getShop()
        shipping_methods = IShippingMethodManagement(shop).getShippingMethods(
            check_validity=True)
        shipping_methods_ids = [sm.getId() for sm in shipping_methods]
        selected_shipping_method = self.request.get("selected_shipping_method")

        # Set selected shipping method
        if selected_shipping_method in shipping_methods_ids:
            customer.selected_shipping_method = \
                safe_unicode(self.request.get("selected_shipping_method"))
        else:
            customer.selected_shipping_method = shipping_methods_ids[0]

        # Set selected payment method type
        customer.selected_payment_method = \
            safe_unicode(self.request.get("selected_payment_method"))

        # Set selected VAT registration
        selected_vat_country = safe_unicode(
            self.request.get("selected_vat_country"))
        selected_vat_number = safe_unicode(
            self.request.get("selected_vat_number"))
        if selected_vat_country == "" or selected_vat_country is None or selected_vat_number is None:
            customer.vatreg = None
        elif selected_vat_country == "XX":
            customer.vatreg = selected_vat_country
        else:
            customer.vatreg = selected_vat_country + selected_vat_number