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)
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)
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