Esempio n. 1
0
 /**
  * Select one of the options and "prepare for cart" with a proper buy request
  */
 protected function _prepareForCart()
 {
     $attributes = $this->_model->getConfigurableAttributesAsArray($this->_product);
     $attribute = reset($attributes);
     $optionValueId = $attribute['values'][0]['value_index'];
     $buyRequest = new \Magento\Framework\Object(['qty' => 5, 'super_attribute' => [$attribute['attribute_id'] => $optionValueId]]);
     $this->_model->prepareForCart($buyRequest, $this->_product);
 }
 /**
  * Select one of the options and "prepare for cart" with a proper buy request
  *
  * @return ProductInterface
  */
 protected function _prepareForCart()
 {
     $product = $this->productRepository->getById(1, true);
     $attributes = $this->model->getConfigurableAttributesAsArray($product);
     $attribute = reset($attributes);
     $optionValueId = $attribute['values'][0]['value_index'];
     $buyRequest = new \Magento\Framework\DataObject(['qty' => 5, 'super_attribute' => [$attribute['attribute_id'] => $optionValueId]]);
     $this->model->prepareForCart($buyRequest, $product);
     return $product;
 }