Ejemplo n.º 1
0
    def isValid(self, product=None):
        """Returns True if the selected shipping method of the current customer
        is within selected shipping methods of this criterion.
        """
        shop = IShopManagement(self.context).getShop()
        sm = IShippingMethodManagement(shop)
        selected_method = sm.getSelectedShippingMethod()

        if self.context.getOperator() == "current":
            if selected_method is not None and \
               selected_method.getId() in self.context.getShippingMethods():
                return True
            else:
                return False
        else:
            for id in self.context.getShippingMethods():

                # Never check validity for itself (context)
                if id == self.context.getId():
                    continue

                shipping_method = sm.getShippingMethod(id)
                if IValidity(shipping_method).isValid() == True:
                    return False
            return True
Ejemplo n.º 2
0
    def stock_information(self):
        """
        """
        shop = IShopManagement(self.context).getShop()
        sm = IStockManagement(shop)

        pvm = IProductVariantsManagement(self.context)

        if pvm.hasVariants() == False:
            stock_information = sm.getStockInformationFor(self.context)
        else:
            product_variant = pvm.getSelectedVariant()

            # First, we try to get information for the selected product variant
            stock_information = sm.getStockInformationFor(product_variant)

            # If nothing is found, we try to get information for parent product
            # variants object.
            if stock_information is None:
                stock_information = sm.getStockInformationFor(self.context)

        if stock_information is None:
            return None

        return IData(stock_information).asDict()
Ejemplo n.º 3
0
    def getTopLevelCategories(self):
        """
        """
        shop = IShopManagement(self.context).getShop()

        cm = ICategoryManagement(shop)
        return cm.getTopLevelCategories()
Ejemplo n.º 4
0
    def getRotatingObjects(self):
        """
        """
        shop = IShopManagement(self.context).getShop()
        cm = ICurrencyManagement(shop)
        
        catalog = getToolByName(self.context, "portal_catalog")
        
        path = self.data.path.encode("utf-8")
        obj = self.context.restrictedTraverse(path)
        
        result = []
        for item in IRotating(obj).getItems(self.data.limit):

            brains = catalog.searchResults(UID = item["uid"])
            product = brains[0].getObject()
            
            standard_price = IPrices(product).getPriceForCustomer(effective=False)
            price = IPrices(product).getPriceForCustomer()
                
            item["for_sale"] = product.getForSale()
            item["standard_price"] = cm.priceToString(standard_price)
            item["price"] = cm.priceToString(price)
            
            result.append(item)
            
        return result
Ejemplo n.º 5
0
    def getStartupDirectoryForCategories(self):
        """
        """
        shop = IShopManagement(self).getShop()
        shop_path = "/".join(shop.getPhysicalPath())

        return shop_path
Ejemplo n.º 6
0
    def getOrders(self):
        """
        """
        shop = IShopManagement(self.context).getShop()
        om = IOrderManagement(shop)
        orders = om.getOrdersForAuthenticatedCustomer()
        wftool = getToolByName(self.context, "portal_workflow")
        ttool = getToolByName(self.context, 'translation_service')

        result = []
        for order in orders:
            # TODO: Get rid of using order view
            order_view = getMultiAdapter((order, self.request), name="order")
            created = ttool.ulocalized_time(order.created(), long_format=True)
            temp = {
                "id": order.getId(),
                "url": order.absolute_url(),
                "price_gross": order_view.getPriceForCustomer(),
                "shipping": order_view.getShipping(),
                "payment": order_view.getPaymentValues(),
                "items_": order_view.getItems(),
                "creation_date": created,
                "state": wftool.getInfoFor(order, "review_state"),
                "tax": order_view.getTax(),
            }
            result.append(temp)

        return result
Ejemplo n.º 7
0
def mailOrderSent(order):
    """Sends email to customer that the order has been sent.
    """
    shop = IShopManagement(order).getShop()

    # Get mail content
    view = getMultiAdapter((order, order.REQUEST), name="mail-order-sent")
    text = view()

    # Get customer
    customer = order.getCustomer()

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

    # Get sender
    sender = IMailAddresses(shop).getSender()

    sendMultipartMail(context=order,
                      sender=sender,
                      receiver=customer.email,
                      subject="Your order %s has been sent." % order.getId(),
                      text=text,
                      charset=charset)
Ejemplo n.º 8
0
    def getMyAccountURL(self):
        """
        """
        shop = IShopManagement(self.context).getShop()
        customer = ICustomerManagement(shop).getAuthenticatedCustomer()

        return customer.absolute_url() + "/" + "my-account"
Ejemplo n.º 9
0
    def process(self, order=None):
        """
        """
        shop = IShopManagement(self.context).getShop()
        callback_url = "%s/nochex?order=%s" % (shop.absolute_url(),
                                               order.UID())
        success_url = "%s/thank-you" % shop.absolute_url()

        pc = IPrices(order)
        price_gross = "%.2f" % pc.getPriceGross()

        info = {
            "merchant_id": NOCHEX_ID,
            "amount": price_gross,
            "order_id": order.getId(),
            "success_url": success_url,
            "callback_url": callback_url,
        }

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

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

        return PaymentResult(NOT_PAYED)
Ejemplo n.º 10
0
def countries(context):
    """
    """
    terms = []
    # terms.append(SimpleTerm("Germany", u"Germany"))
    # terms.append(SimpleTerm("USA", u"USA"))
    # terms.append(SimpleTerm("Polen", u"Polen"))

    shop = IShopManagement(context).getShop()

    if shop is None:
        # BBB: this is ugly because if we create a new address
        #      we dont have any context. try to guess the first EasyShop
        #      in portal_catalog and hope we are in luck!
        # XXX: this breaks if the site has more than one EasyShop instances!!!
        sm = getSiteManager()
        cat_query = sm.portal_catalog.queryCatalog(
            dict(portal_type='EasyShop'))

        if len(cat_query)<1:
            # this is not possible, because we weren't in this vocab if
            # we hadn't an EasyShop instance
            __traceback_info__ = "no Easyshop found in portal_catalog"
            raise Exception

        shop = cat_query[0].getObject()

    for country in shop.getCountries():
        country = safe_unicode(country)
        term_value = queryUtility(IIDNormalizer).normalize(country)
        terms.append(SimpleTerm(term_value, term_value, country))

    return SimpleVocabulary(terms)
Ejemplo n.º 11
0
    def addAddress(self, form):
        """
        """
        shop = IShopManagement(self.context).getShop()
        customer = ICustomerManagement(shop).getAuthenticatedCustomer()

        id = self.context.generateUniqueId("Address")

        customer.invokeFactory("Address", id=id, title=form.get("address1"))
        address = getattr(customer, id)

        # set data
        address.setFirstname(form.get("firstname", ""))
        address.setLastname(form.get("lastname", ""))
        address.setLastname(form.get("companyName", ""))
        address.setAddress1(form.get("address1", ""))
        address.setAddress2(form.get("address2", ""))
        address.setZipCode(form.get("zipCode", ""))
        address.setCity(form.get("city", ""))
        address.setCountry(form.get("country", ""))
        address.setPhone(form.get("phone", ""))

        # Refresh addresses
        kss_core = self.getCommandSet("core")
        kss_zope = self.getCommandSet("zope")

        selector = kss_core.getHtmlIdSelector("manage-address-book")
        kss_zope.refreshViewlet(selector,
                                manager="easyshop.manager.addresses",
                                name="easyshop.addresses")
Ejemplo n.º 12
0
    def isValid(self, product=None):
        """Returns True, if the total width of the cart is greater than the
        entered criteria width.
        """
        shop = IShopManagement(self.context).getShop()
        cart = ICartManagement(shop).getCart()
        
        max_length = 0
        max_width = 0
        total_height = 0
        
        if cart is not None:
            for item in IItemManagement(cart).getItems():
                if max_length < item.getProduct().getLength():
                    max_length = item.getProduct().getLength()
                
                if max_width < item.getProduct().getWidth():
                    max_width = item.getProduct().getWidth()
                    
                total_height += (item.getProduct().getHeight() * item.getAmount())
        
        # Calc cart girth        
        cart_girth = (2 * max_width) +  (2 * total_height) + max_length
        
        if self.context.getOperator() == ">=":
            if cart_girth >= self.context.getCombinedLengthAndGirth():
                return True
        else:
            if cart_girth < self.context.getCombinedLengthAndGirth():
                return True

        return False        
Ejemplo n.º 13
0
    def getCustomerTaxes(self):
        """
        """
        tm = ITaxManagement(IShopManagement(self.context).getShop())
        nc = queryUtility(INumberConverter)

        result = []
        for tax in tm.getCustomerTaxes():
            result.append({
                "id":
                tax.getId(),
                "title":
                tax.Title(),
                "rate":
                nc.floatToTaxString(tax.getRate()),
                "up_link":
                "%s/es_folder_position?position=up&id=%s" %
                (self.context.absolute_url(), tax.getId()),
                "down_link":
                "%s/es_folder_position?position=down&id=%s" %
                (self.context.absolute_url(), tax.getId()),
                "url":
                tax.absolute_url(),
                "amount_of_criteria":
                self._getAmountOfCriteria(tax.getId()),
            })

        return result
Ejemplo n.º 14
0
    def getShippingPrices(self):
        """
        """
        shop = IShopManagement(self.context).getShop()
        sm = IShippingPriceManagement(shop)
        cm = ICurrencyManagement(shop)

        result = []
        for shipping_price in sm.getShippingPrices():

            price = cm.priceToString(shipping_price.getPrice())

            result.append({
                "id":
                shipping_price.getId(),
                "title":
                shipping_price.Title(),
                "description":
                shipping_price.Description(),
                "price":
                price,
                "url":
                shipping_price.absolute_url(),
                "up_url":
                "%s/es_folder_position?position=up&id=%s" %
                (self.context.absolute_url(), shipping_price.getId()),
                "down_url":
                "%s/es_folder_position?position=down&id=%s" %
                (self.context.absolute_url(), shipping_price.getId()),
                "amount_of_criteria":
                self._getAmountOfCriteria(shipping_price.getId())
            })

        return result
Ejemplo n.º 15
0
    def getDiscounts(self):
        """
        """
        shop = IShopManagement(self.context).getShop()
        dm = IDiscountsManagement(shop)
        cm = ICurrencyManagement(shop)

        result = []
        for discount in dm.getDiscounts():

            value = cm.priceToString(discount.getValue())

            result.append({
                "id":
                discount.getId(),
                "title":
                discount.Title(),
                "description":
                discount.Description(),
                "value":
                value,
                "url":
                discount.absolute_url(),
                "up_url":
                "%s/es_folder_position?position=up&id=%s" %
                (self.context.absolute_url(), discount.getId()),
                "down_url":
                "%s/es_folder_position?position=down&id=%s" %
                (self.context.absolute_url(), discount.getId()),
                "amount_of_criteria":
                self._getAmountOfCriteria(discount.getId())
            })

        return result
Ejemplo n.º 16
0
    def addCategory(self):
        """
        """
        category_name = self.request.get("category_name", "")
        if category_name == "":
            return self._showView()
            
        shop = IShopManagement(self.context).getShop()

        putils = getToolByName(self.context, "plone_utils")        
        normalized_id = putils.normalizeString(category_name)

        if base_hasattr(shop, normalized_id) == True:
            putils.addPortalMessage(MESSAGES["CATEGORY_ALREADY_EXISTS"], "error")
            return self._showView()
        else:
            shop.invokeFactory("Category", id=normalized_id, title=category_name)
            putils.addPortalMessage(MESSAGES["ADDED_CATEGORY"])
            
        new_category = shop[normalized_id]
        
        if self.hasSelectedCategories() == True:
            catalog = getToolByName(self.context, "portal_catalog")
            brains = catalog.searchResults(UID = self.selected_categories)            
            parent_categories = [b.getObject() for b in brains]            
            new_category.setParentCategory(parent_categories)
            new_category.reindexObject()

        return self._showView()
Ejemplo n.º 17
0
    def getProducts(self):
        """
        """
        shop = IShopManagement(self.context).getShop()
        pm = IProductManagement(shop)

        result = []
        for product in pm.getProducts():
            result.append({
                "uid": product.UID,
                "title": product.Title,
            })

        # Get start page
        b_start = self.request.get('b_start', 0)
        if b_start == "None":
            b_start = 0

        batch = Batch(result, 20, int(b_start), orphan=0)

        # Calculate Batch
        return {
            "batch": batch,
            "next_url": self._getNextUrl(batch),
            "previous_url": self._getPreviousUrl(batch)
        }
Ejemplo n.º 18
0
    def getCategories(self):
        """
        """
        shop = IShopManagement(self.context).getShop()
        categories = ICategoryManagement(shop).getTopLevelCategories(
            full_objects=False)

        result = []
        for category in categories:

            klass = ""
            if self._isCurrentItem(category) == True:
                klass += "navTreeCurrentItem"

            result.append({
                "klass": klass,
                "url": category.getURL(),
                "description": category.Description,
                "title": category.Title,
                "amount_of_products": category.total_amount_of_products,
                "subcategories": self._getSubCategories(category),
                "products": self._getProducts(category),
            })

        return result
Ejemplo n.º 19
0
    def getPaymentMethods(self):
        """
        """
        shop = IShopManagement(self.context).getShop()
        pm = IPaymentMethodManagement(shop)

        result = []
        for payment_method in pm.getPaymentMethods():
            result.append({
                "id":
                payment_method.getId(),
                "title":
                payment_method.Title(),
                "url":
                payment_method.absolute_url(),
                "up_url":
                "%s/es_folder_position?position=up&id=%s" %
                (self.context.absolute_url(), payment_method.getId()),
                "down_url":
                "%s/es_folder_position?position=down&id=%s" %
                (self.context.absolute_url(), payment_method.getId()),
                "amount_of_criteria":
                self._getAmountOfCriteria(payment_method.getId())
            })

        return result
Ejemplo n.º 20
0
    def getInformationPages(self):
        """
        """
        shop = IShopManagement(self.context).getShop()
        im = IInformationManagement(shop)

        result = []
        for information in im.getInformationPages():

            result.append({
                "id":
                information.getId(),
                "title":
                information.Title(),
                "url":
                information.absolute_url(),
                "description":
                information.Description(),
                "up_url":
                "%s/es_folder_position?position=up&id=%s" %
                (self.context.absolute_url(), information.getId()),
                "down_url":
                "%s/es_folder_position?position=down&id=%s" %
                (self.context.absolute_url(), information.getId()),
                "amount_of_criteria":
                len(information.objectIds()),
            })

        return result
Ejemplo n.º 21
0
def mailOrderSubmitted(order):
    """Sends email to shop owner that an order has been submitted.
    """
    shop = IShopManagement(order).getShop()

    # Get sender and receiver
    mail_addresses = IMailAddresses(shop)
    sender = mail_addresses.getSender()
    receivers = mail_addresses.getReceivers()

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

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

        sendMultipartMail(context=order,
                          sender=sender,
                          receiver=", ".join(receivers),
                          subject="E-Shop: New order",
                          text=text,
                          charset=charset)
Ejemplo n.º 22
0
    def getSelectedShippingMethod(self):
        """
        """
        cm = ICustomerManagement(IShopManagement(self.context).getShop())
        customer = cm.getAuthenticatedCustomer()
        shipping_method_id = customer.selected_shipping_method

        return self.getShippingMethod(shipping_method_id)
Ejemplo n.º 23
0
 def __init__(self, discount, cart_item):
     """
     """
     self.discount = discount
     self.cart_item = cart_item
     self.product = cart_item.getProduct()
     self.taxes = ITaxes(self.product)
     self.shop = IShopManagement(self.product).getShop()
Ejemplo n.º 24
0
    def isValid(self, product=None):
        """Returns False if the PayPal id is not filled in.
        """
        shop = IShopManagement(self.context).getShop()
        if shop.getPayPalId() == "":
            return False

        return super(PayPalValidity, self).isValid(product)
Ejemplo n.º 25
0
    def _getPaymentMethodsAsDL(self):
        """Returns all payment methods as DisplayList.
        """
        dl = DisplayList()
        shop = IShopManagement(self).getShop()
        for method in IPaymentMethodManagement(shop).getPaymentMethods():
            dl.add(method.getId(), method.Title())

        return dl
Ejemplo n.º 26
0
 def getValue(self):
     """
     """
     if self.context.getType() == "absolute":
         cm = ICurrencyManagement(IShopManagement(self.context).getShop())
         return cm.priceToString(self.context.getValue())
     else:
         c = getUtility(INumberConverter)
         return c.floatToTaxString(self.context.getValue())
Ejemplo n.º 27
0
    def getCancellationInstruction(self):
        """
        """
        shop = IShopManagement(self.context).getShop()
        im = IInformationManagement(shop)

        # TODO: Rename to english
        page = im.getInformationPage("cancellation-instructions")
        return page.getText()
Ejemplo n.º 28
0
    def _getShippingMethodsAsDL(self):
        """Returns all shipping methods as DisplayList.
        """
        dl = DisplayList()

        pm = IShippingManagement(IShopManagement(self).getShop())
        for shipping_method in pm.getShippingMethods():
            dl.add(shipping_method.getId(), shipping_method.Title())

        return dl
Ejemplo n.º 29
0
    def _getCountriesAsDL(self):
        """
        """
        dl = DisplayList()
        for country in IShopManagement(self).getShop().getCountries():
            country = safe_unicode(country)
            term_value = queryUtility(IIDNormalizer).normalize(country)
            dl.add(term_value, country)

        return dl
Ejemplo n.º 30
0
    def _getPaymentMethodsAsDL(self):
        """Returns all payment methods as DisplayList.
        """
        dl = DisplayList()

        pm = IPaymentManagement(IShopManagement(self).getShop())
        for payment_method in pm.getPaymentMethods():
            dl.add(payment_method.getId(), payment_method.Title())

        return dl