Ejemplo n.º 1
0
 /**
  * @covers \Magento\GroupedProduct\Service\V1\Product\Link\Data\ProductLink\DataMapper\GroupedProduct::map
  */
 public function testMap()
 {
     $data = [['name' => 'item1', 'custom_attributes' => ['qty' => ['value' => 5]]], ['name' => 'item2']];
     $model = new GroupedProduct();
     $mappedData = $model->map($data);
     $this->assertEquals(5, $mappedData[0]['qty']);
     $this->assertFalse(isset($mappedData[1]['qty']));
 }
 /**
  * @param Controller     $controller
  * @param String         $name
  * @param GroupedProduct $product
  */
 public function __construct($controller, $name, GroupedProduct $product)
 {
     $fields = new FieldList();
     // add quantity etc fields
     // TODO: These should probably be cleaned up and put in composite fields or something
     foreach ($product->ChildProducts() as $child) {
         if (!$child->hasExtension('GroupedCartFormChildHooks')) {
             user_error('Child Products must have GroupedCartFormChildHooks applied.');
         }
         $vars = $child->hasMethod('Variations') ? $child->Variations() : null;
         if ($vars && $vars->count() > 0) {
             foreach ($child->getVariationFields() as $f) {
                 $fields->push($f);
             }
         }
         $fields->push($child->getQuantityField());
     }
     $actions = new FieldList(array(FormAction::create('addtocart', _t('GroupedCartForm.ADD', 'Add to Cart'))));
     // integrate with wishlist module
     if (class_exists('WishList')) {
         $actions->unshift(FormAction::create('addtowishlist', _t('GroupedCartForm.ADDTOWISHLIST', 'Add to Wish List')));
     }
     parent::__construct($controller, $name, $fields, $actions);
 }