示例#1
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)
示例#2
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)
示例#3
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)
示例#4
0
    def getBackToOverViewUrl(self):
        """
        """
        if IShop.providedBy(self.context):
            return None

        parent_category = self.context.getRefs("parent_category")
        if len(parent_category) > 0:
            return parent_category[0].absolute_url()

        shop = IShopManagement(self.context).getShop()
        return shop.absolute_url()
示例#5
0
    def getBackToOverViewUrl(self):
        """
        """
        if IShop.providedBy(self.context):
            return None
        
        parent_category = self.context.getRefs("parent_category")
        if len(parent_category) > 0:
            return parent_category[0].absolute_url()

        shop = IShopManagement(self.context).getShop()
        return shop.absolute_url()
示例#6
0
    def getBackToOverViewUrl(self):
        """
        """
        parent = self.context.aq_inner.aq_parent
        if ICategory.providedBy(parent):
            parent_url = parent.absolute_url()
        elif ICategoriesContainer.providedBy(parent):
            shop = IShopManagement(self.context).getShop()
            parent_url = shop.absolute_url()
        else:
            parent_url = None

        return parent_url
示例#7
0
 def getBackToOverViewUrl(self):
     """
     """
     parent = self.context.aq_inner.aq_parent
     if ICategory.providedBy(parent):
         parent_url = parent.absolute_url()
     elif ICategoriesContainer.providedBy(parent):
         shop = IShopManagement(self.context).getShop()
         parent_url = shop.absolute_url()
     else:
         parent_url = None
         
     return parent_url
示例#8
0
    def getInfo(self):
        """
        """
        batch = self._getBatch()
        # This optimized for speed, as we need _getBatch here anyway.
        # So there is no need of an extra method call within the page 
        # template to get informations we have here already. Same is true 
        # for format infos, see below
                
        parent = self.context.aq_inner.aq_parent
        if ICategory.providedBy(parent):
            parent_url = parent.absolute_url()
        elif ICategoriesContainer.providedBy(parent):
            shop = IShopManagement(self.context).getShop()
            parent_url = shop.absolute_url()
        else:
            parent_url = None
        
        batch_infos = {
            "parent_url"       : parent_url,
            "first_url"        : self._getFirstUrl(batch),
            "previous_url"     : self._getPreviousUrl(batch),
            "previous"         : batch.previous,
            "next_url"         : self._getNextUrl(batch),
            "next"             : batch.next,
            "last_url"         : self._getLastUrl(batch),
            "navigation_list"  : batch.navlist,
            "number_of_pages"  : batch.numpages,
            "page_number"      : batch.pagenumber,
            "amount"           : batch.sequence_length,
        }
        
        sorting = self.request.SESSION.get("sorting")

        f = self.getFormatInfo()
        products_per_line = f["products_per_line"]
        
        line = []
        products = []        
        for index, product in enumerate(batch):

            # Price
            cm = ICurrencyManagement(self.context)
            p = IPrices(product)

            # Effective price
            price = p.getPriceForCustomer()                                
            price = cm.priceToString(price, symbol="symbol", position="before")
            
            # Standard price
            standard_price = p.getPriceForCustomer(effective=False)
            standard_price = cm.priceToString(standard_price, symbol="symbol", position="before")
                                    
            # Image
            image = IImageManagement(product).getMainImage()
            if image is not None:
                image = "%s/image_%s" % (image.absolute_url(), f.get("image_size"))
            
            # Text    
            temp = f.get("text")
            if temp == "description":
                text = product.getDescription()
            elif temp == "short_text":
                text = product.getShortText()
            elif temp == "text":
                text = product.getText()
            else:
                text = ""

            # Title
            temp = f.get("title")
            if temp == "title":
                title = product.Title()
            elif temp == "short_title":
                title = product.getShortTitle()

            try:
                chars = int(f.get("chars"))
            except (TypeError, ValueError):
                chars = 0
            
            if (chars != 0) and (len(title) > chars):
                title = title[:chars]
                title += "..."
                    
            # CSS Class
            if (index + 1) % products_per_line == 0:
                klass = "last"
            else:
                klass = "notlast"
                            
            line.append({
                "title"                    : title,
                "text"                     : text,
                "url"                      : product.absolute_url(),
                "image"                    : image,
                "for_sale"                 : product.getForSale(),
                "price"                    : price,
                "standard_price"           : standard_price,
                "class"                    : klass,
            })
            
            if (index + 1) % products_per_line == 0:
                products.append(line)
                line = []
        
        # the rest
        if len(line) > 0:
            products.append(line)
        
        # Return format infos here, because we need it anyway in this method
        # This is for speed reasons. See above.
        return {
            "products"    : products, 
            "batch_info"  : batch_infos,
            "format_info" : f,
        }
示例#9
0
文件: sitemap.py 项目: viona/Easyshop
 def getShopUrl(self):
     """
     """
     shop = IShopManagement(self.context).getShop()
     return shop.absolute_url()
示例#10
0
    def addToCart(self, redirect=True, add_accessories=True):
        """
        """
        shop = IShopManagement(self.context).getShop()
        cm = ICartManagement(shop)

        cart = cm.getCart()
        if cart is None:
            cart = cm.createCart()

        pvm = IProductVariantsManagement(self.context)
        if pvm.hasVariants():

            # Get the actual "product"
            product = pvm.getSelectedVariant() or pvm.getDefaultVariant()

            # Using here the selected product ensures that we save the right
            # properties. This is important when the selected variant doesn't
            # exist.
            properties = []
            for property in product.getForProperties():
                property_id, selected_option = property.split(":")
                properties.append({
                    "id": property_id,
                    "selected_option": selected_option,
                })
        else:

            # The product is the context
            product = self.context

            # Unlike above we take the properties out of the request, because
            # there is no object wich stores the different properties.
            properties = []
            for property in IPropertyManagement(product).getProperties():
                selected_option_id = self.request.get(
                    "property_%s_%s" % (product.UID(), property.getId()))

                # If nothing is selected we take the first option of the
                # property
                if (selected_option_id is None) or (selected_option_id
                                                    == "select"):
                    property = IPropertyManagement(product).getProperty(
                        property.getId())
                    property_options = property.getOptions()

                    if property_options:
                        selected_option = property.getOptions()[0]
                        selected_option_id = selected_option["id"]
                    else:
                        selected_option_id = ""

                properties.append({
                    "id": property.getId(),
                    "selected_option": selected_option_id
                })

        # get quantity
        quantity = int(
            self.context.request.get("%s_quantity" % self.context.UID(), 1))

        # returns true if the product was already within the cart
        result, item_id = IItemManagement(cart).addItem(
            product, tuple(properties), quantity)

        # Add product to session (for display on add to cart view)
        if self.request.SESSION.get("added-to-cart") is None:
            self.request.SESSION["added-to-cart"] = []
        self.request.SESSION["added-to-cart"].append(item_id)

        # Add the accessories
        if add_accessories == True:
            catalog = getToolByName(self.context, "portal_catalog")
            accessories = tuplize(self.request.get("accessories", []))
            for uid in accessories:
                try:
                    brain = catalog.searchResults(UID=uid)[0]
                except IndexError:
                    continue

                # We reuse the same view with an other context. The context are
                # the accessories
                product = brain.getObject()
                view = getMultiAdapter((product, self.request),
                                       name="addToCart")
                view.addToCart(redirect=False, add_accessories=False)

        if redirect == True:
            # Set portal message
            # putils = getToolByName(self.context, "plone_utils")
            # if result == True:
            #     putils.addPortalMessage(MESSAGES["CART_INCREASED_AMOUNT"])
            # else:
            #     putils.addPortalMessage(MESSAGES["CART_ADDED_PRODUCT"])

            url = "%s/added-to-cart" % shop.absolute_url()
            self.context.request.response.redirect(url)
示例#11
0
 def getShopUrl(self):
     """
     """
     shop = IShopManagement(self.context).getShop()
     return shop.absolute_url()
示例#12
0
    def getInfo(self):
        """
        """
        batch = self._getBatch()
        # This optimized for speed, as we need _getBatch here anyway.
        # So there is no need of an extra method call within the page
        # template to get informations we have here already. Same is true
        # for format infos, see below

        parent = self.context.aq_inner.aq_parent
        if ICategory.providedBy(parent):
            parent_url = parent.absolute_url()
        elif ICategoriesContainer.providedBy(parent):
            shop = IShopManagement(self.context).getShop()
            parent_url = shop.absolute_url()
        else:
            parent_url = None

        batch_infos = {
            "parent_url": parent_url,
            "first_url": self._getFirstUrl(batch),
            "previous_url": self._getPreviousUrl(batch),
            "previous": batch.previous,
            "next_url": self._getNextUrl(batch),
            "next": batch.next,
            "last_url": self._getLastUrl(batch),
            "navigation_list": batch.navlist,
            "number_of_pages": batch.numpages,
            "page_number": batch.pagenumber,
            "amount": batch.sequence_length,
        }

        sorting = self.request.SESSION.get("sorting")

        f = self.getFormatInfo()
        products_per_line = f["products_per_line"]

        line = []
        products = []
        for index, product in enumerate(batch):

            # Price
            cm = ICurrencyManagement(self.context)
            p = IPrices(product)

            # Effective price
            price = p.getPriceForCustomer()
            price = cm.priceToString(price, symbol="symbol", position="before")

            # Standard price
            standard_price = p.getPriceForCustomer(effective=False)
            standard_price = cm.priceToString(standard_price,
                                              symbol="symbol",
                                              position="before")

            # Image
            image = IImageManagement(product).getMainImage()
            if image is not None:
                image = "%s/image_%s" % (image.absolute_url(),
                                         f.get("image_size"))

            # Text
            temp = f.get("text")
            if temp == "description":
                text = product.getDescription()
            elif temp == "short_text":
                text = product.getShortText()
            elif temp == "text":
                text = product.getText()
            else:
                text = ""

            # Title
            temp = f.get("title")
            if temp == "title":
                title = product.Title()
            elif temp == "short_title":
                title = product.getShortTitle()

            try:
                chars = int(f.get("chars"))
            except (TypeError, ValueError):
                chars = 0

            if (chars != 0) and (len(title) > chars):
                title = title[:chars]
                title += "..."

            # CSS Class
            if (index + 1) % products_per_line == 0:
                klass = "last"
            else:
                klass = "notlast"

            line.append({
                "title": title,
                "text": text,
                "url": product.absolute_url(),
                "image": image,
                "for_sale": product.getForSale(),
                "price": price,
                "standard_price": standard_price,
                "class": klass,
            })

            if (index + 1) % products_per_line == 0:
                products.append(line)
                line = []

        # the rest
        if len(line) > 0:
            products.append(line)

        # Return format infos here, because we need it anyway in this method
        # This is for speed reasons. See above.
        return {
            "products": products,
            "batch_info": batch_infos,
            "format_info": f,
        }
示例#13
0
    def process(self, order=None):
        """
        """
        context = aq_inner(self.context)
        shop = IShopManagement(context).getShop()
        customer = ICustomerManagement(shop).getAuthenticatedCustomer()

        line_items = []
        for i, item in enumerate(IItemManagement(order).getItems()):
            if item.getProductTax() > 0:
                tax = "Y"
            else:
                tax = "N"

            line_items.append((
                str(i+1),
                item.getProduct().Title(),
                str(item.getProductQuantity()),
                str(item.getProductPriceGross()),
                tax,
            ))

        amount = "%.2f" % IPrices(order).getPriceForCustomer()

        mpay24_url = context.getUrl()
        mpay24_merchant_id = context.getMerchant_id()
        mpay24_mdxi = context.getMdxi()

        conn_query = "OPERATION=SELECTPAYMENT&MERCHANTID=%s&MDXI=%s" % \
            (mpay24_merchant_id,
             quote(mpay24_mdxi % dict(tid=order.id,
                                      price=amount,
                                      site_url=shop.absolute_url())),)

        conn_string = "%s?%s" % (mpay24_url, conn_query)

        h = httplib2.Http('.cache',timeout=10)

        try:
            http_response, data = h.request(conn_string,"GET",)
        except:
            return PaymentResult(ERROR,_('MPAY24 connection timeout'))

        if data:
            data_dict = dict([part.split('=') for part in data.split('&')])

            if data_dict.get('STATUS','')=='ERROR':
                return PaymentResult(ERROR,"%s\n%s" % \
                    (unquote(data_dict.get('RETURNCODE','')),
                     unquote(conn_string)))
            elif data_dict.get('RETURNCODE','')=='REDIRECT':
                new_loc = data_dict.get('LOCATION','').strip()

                # save redirection URL in cookie for later usage
                context.REQUEST.RESPONSE.setCookie(
                    REDIR_COOKIE_NAME,
                    quote(encodestring(new_loc)),
                    path='/',
                )

                return PaymentResult('SUCCESS', '')
            else:
                return PaymentResult(ERROR, data_dict)

        return PaymentResult(ERROR,_("no data"))