/**
  * Converts a specified rate model to a shipping method data object.
  *
  * @param \Magento\Quote\Model\Quote\Item $item
  * @return array
  * @throws \Exception
  */
 public function modelToDataObject($item)
 {
     $this->eventManager->dispatch('items_additional_data', ['item' => $item]);
     $items = $item->toArray();
     $items['options'] = $this->getFormattedOptionValue($item);
     $itemsData = $this->totalsItemFactory->create();
     $this->dataObjectHelper->populateWithArray($itemsData, $items, '\\Magento\\Quote\\Api\\Data\\TotalsItemInterface');
     return $itemsData;
 }
Example #2
0
 public function testToArray()
 {
     $productMock = $this->generateProductMock(self::PRODUCT_ID, self::PRODUCT_TYPE, self::PRODUCT_SKU, self::PRODUCT_NAME, self::PRODUCT_WEIGHT, self::PRODUCT_TAX_CLASS_ID, self::PRODUCT_COST);
     $this->model->setProduct($productMock);
     $toArrayValue = ['a' => 'b'];
     $productMock->expects($this->once())->method('toArray')->will($this->returnValue($toArrayValue));
     $data = $this->model->toArray();
     $this->assertEquals($toArrayValue, $data['product']);
 }