예제 #1
0
    def add_template_context(self,
                             context,
                             request,
                             selected_options,
                             default_view_tax=False,
                             **kwargs):
        """
        Add context for the product template.
        Return the updated context.
        """
        from product.utils import productvariation_details, serialize_options

        selected_options = self._unique_ids_from_options(selected_options)

        options = serialize_options(self, selected_options)
        if not 'options' in context:
            context['options'] = options
        else:
            curr = list(context['options'])
            curr.extend(list(options))
            context['options'] = curr

        details = productvariation_details(self.product, default_view_tax,
                                           request.user)
        if 'details' in context:
            context['details'].update(details)
        else:
            context['details'] = details

        return context
예제 #2
0
파일: tests.py 프로젝트: DrOctogon/Satchmo
    def test_reordered(self):
        p = Product.objects.get(slug='dj-rocks')

        pv = p.configurableproduct.productvariation_set.all()[0]
        orig_key = pv.optionkey
        orig_detl = productvariation_details(p, False, None, create=True)

        sizegroup = OptionGroup.objects.get(name="sizes")
        sizegroup.sort_order = 100
        sizegroup.save()

        # reverse ordering
        for opt in sizegroup.option_set.all():
            opt.sort_order = 100-opt.sort_order
            opt.save()

        serialized = serialize_options(p.configurableproduct)
        self.assert_(len(serialized), 2)
        self.assertEqual(serialized[1]['id'], 1)
        got_vals = [opt.value for opt in serialized[1]['items']]
        self.assertEqual(got_vals, ['L','M','S'])

        pv2 = ProductVariation.objects.get(pk=pv.pk)
        self.assertEqual(orig_key, pv2.optionkey)
        reorder_detl = productvariation_details(p, False, None)
        self.assertEqual(orig_detl, reorder_detl)
예제 #3
0
    def test_reordered(self):
        p = Product.objects.get(slug='dj-rocks')

        pv = p.configurableproduct.productvariation_set.all()[0]
        orig_key = pv.optionkey
        orig_detl = productvariation_details(p, False, None, create=True)

        sizegroup = OptionGroup.objects.get(name="sizes")
        sizegroup.sort_order = 100
        sizegroup.save()

        # reverse ordering
        for opt in sizegroup.option_set.all():
            opt.sort_order = 100 - opt.sort_order
            opt.save()

        serialized = serialize_options(p.configurableproduct)
        self.assert_(len(serialized), 2)
        self.assertEqual(serialized[1]['id'], 1)
        got_vals = [opt.value for opt in serialized[1]['items']]
        self.assertEqual(got_vals, ['L', 'M', 'S'])

        pv2 = ProductVariation.objects.get(pk=pv.pk)
        self.assertEqual(orig_key, pv2.optionkey)
        reorder_detl = productvariation_details(p, False, None)
        self.assertEqual(orig_detl, reorder_detl)
예제 #4
0
파일: models.py 프로젝트: hnejadi/EShop-2
    def add_template_context(self, context, request, selected_options, default_view_tax=False, **kwargs):
        """
        Add context for the product template.
        Return the updated context.
        """
        from product.utils import productvariation_details, serialize_options

        selected_options = self._unique_ids_from_options(selected_options)

        options = serialize_options(self, selected_options)
        if not 'options' in context:
            context['options'] = options
        else:
            curr = list(context['options'])
            curr.extend(list(options))
            context['options'] = curr

        details = productvariation_details(self.product, default_view_tax,
                                           request.user)
        if 'details' in context:
            context['details'].update(details)
        else:
            context['details'] = details

        return context
예제 #5
0
파일: tests.py 프로젝트: DrOctogon/Satchmo
 def test_base_sort_order(self):
     p = Product.objects.get(slug='dj-rocks')
     serialized = serialize_options(p.configurableproduct)
     self.assert_(len(serialized), 2)
     self.assertEqual(serialized[0]['id'], 1)
     got_vals = [opt.value for opt in serialized[0]['items']]
     self.assertEqual(got_vals, ['S','M','L'])
     self.assertEqual(serialized[1]['id'], 2)
예제 #6
0
 def test_base_sort_order(self):
     p = Product.objects.get(slug='dj-rocks')
     serialized = serialize_options(p.configurableproduct)
     self.assert_(len(serialized), 2)
     self.assertEqual(serialized[0]['id'], 1)
     got_vals = [opt.value for opt in serialized[0]['items']]
     self.assertEqual(got_vals, ['S', 'M', 'L'])
     self.assertEqual(serialized[1]['id'], 2)
예제 #7
0
파일: models.py 프로젝트: 34/T
    def add_template_context(self, context, selected_options, **kwargs):
        """
        Add context for the product template.
        Return the updated context.
        """
        from product.utils import serialize_options

        options = serialize_options(self, selected_options)
        if not 'options' in context:
            context['options'] = options
        else:
            curr = list(context['options'])
            curr.extend(list(options))
            context['options'] = curr

        return context
예제 #8
0
    def add_template_context(self, context, selected_options, **kwargs):
        """
        Add context for the product template.
        Return the updated context.
        """
        from product.utils import serialize_options

        options = serialize_options(self, selected_options)
        if not 'options' in context:
            context['options'] = options
        else:
            curr = list(context['options'])
            curr.extend(list(options))
            context['options'] = curr

        return context