def getStockInformation(self): """ """ shop = self._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()
def afterSetUp(self): """ """ super(TestStockInformationData, self).afterSetUp() container = self.shop["stock-information"] container.invokeFactory("StockInformation", id="s1") sm = IStockManagement(self.shop) self.si = sm.getStockInformationFor(self.shop.products.product_1)
def testgetStockInformationFor_1(self): """ """ container = self.shop["stock-information"] container.invokeFactory("StockInformation", id="s1") sm = IStockManagement(self.shop) valid_stock_information = sm.getStockInformationFor(self.shop.products.product_1) self.assertEqual(valid_stock_information.getId(), "s1")
def testgetStockInformationFor_1(self): """ """ container = self.shop["stock-information"] container.invokeFactory("StockInformation", id="s1") sm = IStockManagement(self.shop) valid_stock_information = sm.getStockInformationFor( self.shop.products.product_1) self.assertEqual(valid_stock_information.getId(), "s1")
def testGetStockInformations(self): """ """ container = self.shop["stock-information"] container.invokeFactory("StockInformation", id="s1") container.invokeFactory("StockInformation", id="s2") container.invokeFactory("StockInformation", id="s3") sm = IStockManagement(self.shop) ids = [s.getId() for s in sm.getStockInformations()] self.assertEqual(ids, ["s1", "s2", "s3"])
def testRemoveCart(self): """ """ view = getMultiAdapter((self.shop.products.product_1, self.shop.products.product_1.REQUEST), name="addToCart") view.addToCart() view.addToCart() view = getMultiAdapter((self.shop.products.product_2, self.shop.products.product_2.REQUEST), name="addToCart") view.addToCart() cart = ICartManagement(self.shop).getCart() sm = IStockManagement(self.shop) sm.removeCart(cart) self.assertEqual(self.shop.products.product_1.getStockAmount(), 8.0) self.assertEqual(self.shop.products.product_2.getStockAmount(), 19.0)
def getStockInformations(self): """ """ shop = IShopManagement(self.context).getShop() sm = IStockManagement(shop) result = [] for stock_information in sm.getStockInformations(): data = IData(stock_information).asDict() result.append({ "id" : stock_information.getId(), "title" : stock_information.Title(), "description" : stock_information.Description(), "available" : data["available"], "time_period" : data["time_period"], "url" : stock_information.absolute_url(), "up_url" : "%s/es_folder_position?position=up&id=%s" % (self.context.absolute_url(), stock_information.getId()), "down_url" : "%s/es_folder_position?position=down&id=%s" % (self.context.absolute_url(), stock_information.getId()), "amount_of_criteria" : len(stock_information.objectIds()), }) return result
def handle_buy_action(self, action, data): """Buys a cart. """ putils = getToolByName(self.context, "plone_utils") # add order om = IOrderManagement(self.context) new_order = om.addOrder() # Set message to shop owner new_order.setMessage(self.context.request.get("form.message", "")) # process payment result = IPaymentProcessing(new_order).process() # Need error for payment methods for which the customer has to pay at # any case The order process should not go on if the customer is not # able to pay. if result.code == ERROR: om.deleteOrder(new_order.id) putils.addPortalMessage(result.message, type=u"error") ICheckoutManagement( self.context).redirectToNextURL("ERROR_PAYMENT") return "" else: cm = ICartManagement(self.context) # Decrease stock IStockManagement(self.context).removeCart(cm.getCart()) # Delete cart cm.deleteCart() # Set order to pending (Mails will be sent) wftool = getToolByName(self.context, "portal_workflow") wftool.doActionFor(new_order, "submit") putils.addPortalMessage(MESSAGES["ORDER_RECEIVED"]) if result.code == PAYED: # Set order to payed (Mails will be sent) wftool = getToolByName(self.context, "portal_workflow") # We need a new security manager here, because this transaction # should usually just be allowed by a Manager except here. old_sm = getSecurityManager() tmp_user = UnrestrictedUser(old_sm.getUser().getId(), '', ['Manager'], '') portal = getToolByName(self.context, 'portal_url').getPortalObject() tmp_user = tmp_user.__of__(portal.acl_users) newSecurityManager(None, tmp_user) wftool.doActionFor(new_order, "pay_not_sent") ## Reset security manager setSecurityManager(old_sm) # Redirect customer = \ ICustomerManagement(self.context).getAuthenticatedCustomer() selected_payment_method = \ IPaymentInformationManagement(customer).getSelectedPaymentMethod() if not IAsynchronPaymentMethod.providedBy(selected_payment_method): ICheckoutManagement(self.context).redirectToNextURL("BUYED_ORDER")