Пример #1
0
 def test_misc(self):
     # really contrived example to get coverage in pvscore.lib.cart
     cust = self.get_customer()
     order = cust.get_active_orders()[0]
     cart = Cart(self.site)
     prod = self.get_prod()
     camp = cust.campaign
     prod = order.items[0].product
     # KB: [2013-02-20]: MOD ATTR TestCatalog.test_misc : Allow for attributes.
     cart.add_item(prod, cust.campaign)
     assert int(cart.total) == int(prod.get_price(camp))
Пример #2
0
    def _site_purchase(self, cust, cart=None):  #pylint: disable-msg=R0912,R0915
        """ KB: [2013-02-20]: MOD ATTR CustomerController._site_purchase : Allow for attributes passed in the post """
        bill = self._create_billing(cust)
        campaign = Campaign.load(cust.campaign_id)

        if not cart:
            cart = Cart()
            product_skus = self.request.POST.getall('product_sku')
            for sku in product_skus:
                prod = Product.find_by_sku(self.enterprise_id, campaign, sku)
                if prod:
                    cart.add_item(product=prod,
                                  campaign=cust.campaign,
                                  start_dt=self.request.POST.get('bill_start_dt')
                                  )
                else:
                    self.flash("No such product sku: %s" % sku)
                    self.raise_redirect(self.request.referrer)
        order = cust.add_order(cart, None, self.enterprise_id, campaign,
                               order_note=self.request.POST.get('order_note'))
        return self._bill_credit_card(cust, order, bill)
Пример #3
0
 def _add_order_impl(self, customer_id, product_ids, attributes, prices, user, discount_id, campaign_id, incl_tax=True):   #pylint: disable-msg=R0913
     """ KB: [2013-02-20]:
     attributes = [{quantity : 0, product : <Product...>}, {...}]
     """
     cust = Customer.load(customer_id)
     self.forbid_if(not cust or cust.campaign.company.enterprise_id != self.enterprise_id)
     cart = Cart()
     campaign_id = campaign_id if campaign_id else cust.campaign_id
     cart.discount_id = discount_id
     for pid in product_ids.keys():
         quantity = product_ids[pid]
         price = prices[pid] if prices and pid in prices else None
         attrs = {}
         for attr in [attr['attribute_product'] for attr in attributes.values() if str(attr['parent_product'].product_id) == pid]:
             attrs[attr.product_id] = { 'quantity' : 0,
                                        'product' : attr}
         cart.add_item(product=Product.load(pid),
                       campaign=cust.campaign,
                       quantity=quantity,
                       attributes=attrs,
                       base_price=price)
     order = cust.add_order(cart, user, self.enterprise_id, cust.campaign, incl_tax=incl_tax)
     order.flush()
     return order.order_id