def test_cart_article_listing(self):
        shopping_site = IShoppingSite(self.portal)
        self.assertEqual(shopping_site.cart_article_listing(), [])

        session = shopping_site.getSessionData(create=True)
        session.set('collective.cart.core', {'articles': {'1': 'ARTICLE1', '2': 'ARTICLE2'}})
        self.assertEqual(shopping_site.cart_article_listing(), ['ARTICLE1', 'ARTICLE2'])
예제 #2
0
    def add_to_cart(self, **kwargs):
        """Add Article to cart"""
        shopping_site = IShoppingSite(self.context)
        cart = shopping_site.cart()
        if cart is None:
            session = self.getSessionData(create=True)
            session.set("collective.cart.core", {})
        else:
            session = self.getSessionData(create=False)

        articles = IShoppingSite(self.context).cart_articles()
        if not articles:
            articles = SessionArticles()

        uuid = IUUID(self.context)

        if uuid in articles:
            items = articles[uuid]
            self._update_existing_cart_article(items, **kwargs)

        else:
            items = {
                "id": uuid,
                "title": self.context.Title(),
                "description": self.context.Description(),
                "url": self.context.absolute_url(),
            }
            items.update(kwargs)

        articles[uuid] = items
        shopping_site.update_cart("articles", articles)
    def test_cart(self):
        shopping_site = IShoppingSite(self.portal)
        self.assertIsNone(shopping_site.cart())

        session = shopping_site.getSessionData(create=True)
        session.set('collective.cart.core', 'CART')
        self.assertEqual(shopping_site.cart(), 'CART')
    def test_update_next_order_id(self, IOrderContainerAdapter):
        alsoProvides(self.portal, IShoppingSiteRoot)
        adapter = IShoppingSite(self.portal)
        adapter.update_next_order_id()
        self.assertFalse(IOrderContainerAdapter.called)

        self.create_content('collective.cart.core.OrderContainer')
        adapter.update_next_order_id()
        self.assertTrue(IOrderContainerAdapter().update_next_order_id.called)
    def test_get_cart_article(self):
        shopping_site = IShoppingSite(self.portal)
        self.assertIsNone(shopping_site.get_cart_article('1'))

        session = shopping_site.getSessionData(create=True)
        session.set('collective.cart.core', {'articles': {'1': 'ARTICLE1', '2': 'ARTICLE2'}})

        self.assertIsNone(shopping_site.get_cart_article('3'))
        self.assertEqual(shopping_site.get_cart_article('2'), 'ARTICLE2')
    def test_cart_articles(self):
        shopping_site = IShoppingSite(self.portal)
        self.assertIsNone(shopping_site.cart_articles())

        session = shopping_site.getSessionData(create=True)
        session.set('collective.cart.core', {})
        self.assertIsNone(shopping_site.cart_articles())

        session.set('collective.cart.core', {'articles': 'ARTICLES'})
        self.assertEqual(shopping_site.cart_articles(), 'ARTICLES')
    def test_get_order(self):
        adapter = IShoppingSite(self.portal)
        self.assertIsNone(adapter.get_order('1'))

        alsoProvides(self.portal, IShoppingSiteRoot)
        container = self.create_content('collective.cart.core.OrderContainer')
        self.assertIsNone(adapter.get_order('1'))

        order1 = self.create_content('collective.cart.core.Order', container, id='1')
        self.assertIsNone(adapter.get_order('2'))
        self.assertEqual(adapter.get_order('1'), order1)
    def test_clear_cart(self):
        shopping_site = IShoppingSite(self.portal)
        self.assertIsNone(shopping_site.clear_cart())

        session = shopping_site.getSessionData(create=True)
        session.set('collective.cart.core', {})
        self.assertIsNone(shopping_site.clear_cart())
        self.assertIsNone(session.get('collective.cart.core'))

        session.set('collective.cart.core', {'articles': {'1': 'ARTICLE1'}})
        self.assertIsNone(shopping_site.clear_cart())
        self.assertIsNone(session.get('collective.cart.core'))
예제 #9
0
    def update(self):
        form = self.request.form
        uuid = form.get("form.buttons.RemoveArticle", None)

        if uuid is not None:

            authenticator = self.context.restrictedTraverse("@@authenticator")
            if not authenticator.verify():
                raise Forbidden()

            shopping_site = IShoppingSite(self.context)
            shopping_site.remove_cart_articles(uuid)
            if not shopping_site.cart_articles():
                current_base_url = self.context.restrictedTraverse("plone_context_state").current_base_url()
                return self.request.response.redirect(current_base_url)
    def test_clean_articles_in_cart(self):
        from plone.uuid.interfaces import IUUID
        adapter = IShoppingSite(self.portal)
        self.assertIsNone(adapter.clean_articles_in_cart())

        article1 = self.create_content('collective.cart.core.Article', id='1')
        article2 = self.create_content('collective.cart.core.Article', id='2')
        uuid1 = IUUID(article1)
        uuid2 = IUUID(article2)
        session = adapter.getSessionData(create=True)
        session.set('collective.cart.core', {'articles': {uuid1: 'ARTICLE1', uuid2: 'ARTICLE2'}})
        self.assertEqual(adapter.clean_articles_in_cart(), {uuid1: 'ARTICLE1', uuid2: 'ARTICLE2'})

        self.portal.manage_delObjects(['1', '2'])
        self.assertEqual(adapter.clean_articles_in_cart(), {})
    def test_create_order(self):
        adapter = IShoppingSite(self.portal)
        self.assertIsNone(adapter.create_order())

        order_container = self.create_content('collective.cart.core.OrderContainer')
        adapter.order_container = mock.Mock(return_value=order_container)

        article1 = {
            'id': '1',
            'title': 'Ärticle1',
            'description': 'Description of Ärticle1',
        }
        cart_articles = {'1': article1}
        adapter.cart_articles = mock.Mock(return_value=cart_articles)

        adapter.update_next_order_id = mock.Mock()
        order1 = adapter.create_order()
        self.assertEqual(order1.id, '1')

        order_article1 = order1['1']
        self.assertEqual(order_article1.title, article1['title'])
        self.assertEqual(order_article1.description, article1['description'])

        order3 = adapter.create_order('3')
        self.assertEqual(order3.id, '3')
    def test_update_cart(self):
        adapter = IShoppingSite(self.portal)
        adapter.update_cart('name', 'NAME')
        self.assertIsNone(adapter.getSessionData(create=False))

        session = adapter.getSessionData(create=True)
        session.set('collective.cart.core', {})
        adapter.update_cart('name', 'NAME')
        self.assertEqual(session.get('collective.cart.core'), {'name': 'NAME'})
    def test_remove_cart_articles(self):
        shopping_site = IShoppingSite(self.portal)
        session = shopping_site.getSessionData(create=True)
        session.set('collective.cart.core', {'articles': {'1': 'ARTICLE1', '2': 'ARTICLE2', '3': 'ARTICLE3'}})

        self.assertEqual(shopping_site.remove_cart_articles('4'), [])
        self.assertEqual(shopping_site.cart_articles(), {'1': 'ARTICLE1', '2': 'ARTICLE2', '3': 'ARTICLE3'})

        self.assertEqual(shopping_site.remove_cart_articles(['2', '3']), ['ARTICLE2', 'ARTICLE3'])
        self.assertEqual(shopping_site.cart_articles(), {'1': 'ARTICLE1'})

        self.assertEqual(shopping_site.remove_cart_articles('1'), ['ARTICLE1'])
        self.assertEqual(shopping_site.cart_articles(), {})
예제 #14
0
 def cart_url(self):
     shop = IShoppingSite(self.context).shop()
     return '{}/@@cart'.format(shop.absolute_url())
    def test_remove_from_cart(self):
        adapter = IShoppingSite(self.portal)
        self.assertIsNone(adapter.cart())
        self.assertIsNone(adapter.remove_from_cart('name'))
        self.assertIsNone(adapter.cart())

        session = adapter.getSessionData(create=True)
        session.set('collective.cart.core', {})
        self.assertEqual(adapter.cart(), {})
        self.assertIsNone(adapter.remove_from_cart('name'))
        self.assertEqual(adapter.cart(), {})

        session.set('collective.cart.core', {'name': 'Name'})
        self.assertEqual(adapter.cart(), {'name': 'Name'})
        self.assertEqual(adapter.remove_from_cart('name'), 'Name')
        self.assertEqual(adapter.cart(), {})