def setUp(self): layer = self.globs['layer'] self.globs.update({ 'portal': layer['portal'], 'portal_url': layer['portal'].absolute_url(), 'browser': Browser(layer['app']), }) ztc.utils.setupCoreSessions(layer['app']) portal = self.globs['portal'] browser = self.globs['browser'] portal_url = self.globs['portal_url'] browser.setBaseUrl(portal_url) browser.handleErrors = True portal.error_log._ignored_exceptions = () setRoles(portal, TEST_USER_ID, ['Manager']) portal.invokeFactory( 'CartFolder', 'cfolder', ) cfolder = portal.cfolder cfolder.reindexObject() portal.invokeFactory( 'Document', 'document01', title='Document01', ) document01 = portal.document01 document01.reindexObject() alsoProvides(document01, IAddableToCart) IAnnotations(document01)['collective.cart.core'] = ProductAnnotations() product01 = IProduct(document01) product01.price = 10.0 product01.stock = 20 product01.unlimited_stock = False product01.max_addable_quantity = 30 portal.invokeFactory( 'Document', 'document02', title='Document02', ) document02 = portal.document02 document02.reindexObject() alsoProvides(document02, IAddableToCart) IAnnotations(document02)['collective.cart.core'] = ProductAnnotations() product02 = IProduct(document02) product02.price = 5.0 product02.unlimited_stock = True transaction.commit()
def setUp(self): layer = self.globs['layer'] self.globs.update({ 'portal': layer['portal'], 'portal_url': layer['portal'].absolute_url(), 'browser': Browser(layer['app']), }) ztc.utils.setupCoreSessions(layer['app']) portal = self.globs['portal'] browser = self.globs['browser'] portal_url = self.globs['portal_url'] browser.setBaseUrl(portal_url) browser.handleErrors = True portal.error_log._ignored_exceptions = () setRoles(portal, TEST_USER_ID, ['Manager']) portal.invokeFactory( 'CartFolder', 'cfolder', title='CartFolder', ) cfolder = portal.cfolder cfolder.reindexObject() portal.invokeFactory( 'Document', 'document01', title='Document01', ) portal.invokeFactory( 'Document', 'doc01', title='Product01', ) doc01 = portal.doc01 doc01.reindexObject() alsoProvides(doc01, IAddableToCart) IAnnotations(doc01)['collective.cart.core'] = ProductAnnotations() product01 = IProduct(doc01) product01.price = 10.0 product01.stock = 10 product01.unlimited_stock = False product01.max_addable_quantity = 20 transaction.commit()
def fields(self): context = aq_inner(self.context) product = IProduct(context) res = [] price = dict( label=_(u'Price'), description='Input Price.', field= '<input type="text" name="price" id="price" value="%s" size="6" />' % product.price, ) res.append(price) unlimited_stock_field = '<input type="checkbox" name="unlimited_stock" id="unlimited_stock" value="on" />' if product.unlimited_stock == True: unlimited_stock_field = '<input type="checkbox" name="unlimited_stock" id="unlimited_stock" value="on" checked="checked" />' unlimited_stock = dict( label=_(u'Unlimited Stock'), description=_( u'Check this if you have unlimited amount of stock.'), field=unlimited_stock_field, ) res.append(unlimited_stock) stock = dict( label=_(u'Stock'), description='Input Stock.', field= '<input type="text" name="stock" id="stock" value="%s" size="5" />' % product.stock, ) res.append(stock) max_addable_quantity = dict( label=_(u'Maximum Addable Quantity'), description=_( 'You need to specify this if you checked Unlimited Stock.'), field= '<input type="text" name="max_addable_quantity" id="max_addable_quantity" value="%s" size="5" />' % product.max_addable_quantity, ) res.append(max_addable_quantity) return res
def __call__(self): form = self.request.form if form.get('form.button.save', None) is not None: context = aq_inner(self.context) product = IProduct(context) re = getUtility(IRegularExpression) price = form.get('price') if re.float(price): product.price = IPortal(context).decimal_price(price) unlimited_stock = form.get('unlimited_stock') if unlimited_stock == 'on': product.unlimited_stock = True if unlimited_stock != 'on': product.unlimited_stock = False stock = form.get('stock') if re.integer(stock): product.stock = int(stock) max_addable_quantity = form.get('max_addable_quantity') if re.integer(max_addable_quantity): product.max_addable_quantity = int(max_addable_quantity) return self.template()
def update(self): form = self.request.form if form.get("form.button.UpdateProductBasic", None) is not None: context = aq_inner(self.context) product = IProduct(context) re = getUtility(IRegularExpression) price = form.get("price") if re.float(price): product.price = IPortal(context).decimal_price(price) unlimited_stock = form.get("unlimited_stock") if unlimited_stock == "on": product.unlimited_stock = True if unlimited_stock != "on": product.unlimited_stock = False stock = form.get("stock") if re.integer(stock): product.stock = int(stock) max_addable_quantity = form.get("max_addable_quantity") if re.integer(max_addable_quantity): product.max_addable_quantity = int(max_addable_quantity) return self.request.response.redirect(self.current_url)
def setUp(self): layer = self.globs['layer'] # Update global variables within the tests. self.globs.update({ 'portal': layer['portal'], 'portal_url': layer['portal'].absolute_url(), 'browser': Browser(layer['app']), }) ztc.utils.setupCoreSessions(layer['app']) portal = self.globs['portal'] browser = self.globs['browser'] portal_url = self.globs['portal_url'] browser.setBaseUrl(portal_url) browser.handleErrors = True portal.error_log._ignored_exceptions = () setRoles(portal, TEST_USER_ID, ['Manager']) portal.invokeFactory('CartFolder', 'cfolder') portal.invokeFactory( 'ShippingMethod', 'method01', title="ShippingMethod01", base_charge=10.0, weight_charge=5.0, ) method01 = portal.method01 method01.reindexObject() ## Create Product00 portal.invokeFactory( 'Document', 'doc00', title='Product00', description='Description of Product00', ) doc00 = portal.doc00 alsoProvides(doc00, IAddableToCart) IAnnotations(doc00)['collective.cart.core'] = ProductAnnotations() product00 = IProduct(doc00) product00.price = Decimal('100.00') product00.unlimited_stock = True product00.max_addable_quantity = 5 ## Create Product01 portal.invokeFactory( 'Document', 'doc01', title='Product01', description='Description of Product01', ) doc01 = portal.doc01 alsoProvides(doc01, IAddableToCart) IAnnotations(doc01)['collective.cart.core'] = ProductAnnotations() product01 = IProduct(doc01) product01.price = Decimal('10.00') product01.stock = 50 product01.max_addable_quantity = 30 ## Create Product02 portal.invokeFactory( 'Document', 'doc02', title='Product02', description='Description of Product02', ) doc02 = portal.doc02 alsoProvides(doc02, IAddableToCart) IAnnotations(doc02)['collective.cart.core'] = ProductAnnotations() product02 = IProduct(doc02) product02.price = Decimal('5.00') product02.stock = 20 product02.max_addable_quantity = 50 transaction.commit()
def product(self): context = aq_inner(self.context) catalog = getToolByName(context, 'portal_catalog') query = dict(UID=self.uid) obj = catalog.unrestrictedSearchResults(query)[0].getObject() return IProduct(obj)