totalManager = $this->getObject(TotalsInformationManagementInterface::class); $this->totalsInformationFactory = $this->getObject(TotalsInformationInterfaceFactory::class); $this->addressFactory = $this->getObject(AddressInterfaceFactory::class); $this->stockRegistryStorage = $this->getObject(StockRegistryStorage::class); $this->productBuilder = $this->getObject(ProductBuilder::class); $this->taxClassBuilder = $this->getObject(TaxClassBuilder::class); $this->guestCartBuilder = $this->getObject(GuestCartBuilder::class); } /** * Ensure that when totals are collected our tax request being sent to Vertex also sends the Product's Tax Class * * @magentoConfigFixture default_store tax/vertex_settings/enable_vertex 1 * @magentoConfigFixture default_store tax/vertex_settings/api_url https://example.org/CalculateTax70 * @magentoDbIsolation enabled * * @throws \Magento\Framework\Exception\CouldNotSaveException * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\LocalizedException * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\StateException * @return void */ public function testOutgoingRequestContainsProductTaxClass() { $taxClassId = $this->createTaxClass(static::TAX_CLASS_NAME); $product = $this->createProduct($taxClassId); $cart = $this->createCartWithProduct($product); $soapClient = $this->createPartialMock(\SoapClient::class, ['CalculateTax70']); $soapClient->expects($this->atLeastOnce()) ->method('CalculateTax70') ->with( $this->callback( function (\stdClass $request) { $lineItems = $request->QuotationRequest->LineItem; foreach ($lineItems as $lineItem) { $product = $lineItem->Product; if ($product->_ === static::PRODUCT_SKU) { $this->assertEquals(static::TAX_CLASS_NAME, $product->productClass); return true; } } $this->fail( 'Product with SKU "' . static::PRODUCT_SKU . '" not found in Vertex Request:' . PHP_EOL . print_r($request, true) ); return false; } ) ) ->willReturn(new \stdClass()); $this->getSoapFactory()->setSoapClient($soapClient); $address = $this->createShippingAddress(); /** @var TotalsInformationInterface $totalsInfo */ $totalsInfo = $this->totalsInformationFactory->create(); $totalsInfo->setAddress($address); $totalsInfo->setShippingCarrierCode('flatrate'); $totalsInfo->setShippingMethodCode('flatrate'); $this->totalManager->calculate($cart->getId(), $totalsInfo); } /** * Creates a guest cart containing 1 of the provided product * * @param ProductInterface $product * @return \Magento\Quote\Api\Data\CartInterface * @throws \Magento\Framework\Exception\CouldNotSaveException * @throws \Magento\Framework\Exception\NoSuchEntityException */ private function createCartWithProduct(ProductInterface $product) { return $this->guestCartBuilder->setItems() ->addItem($product) ->create(); } /** * Create and save our test's needed Product * * @param int|string $taxClassId * @return ProductInterface * @throws \Magento\Framework\Exception\CouldNotSaveException * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\StateException */ private function createProduct($taxClassId) { return $this->productBuilder->createExampleProduct( function (ProductInterface $product) use ($taxClassId) { $product->setCustomAttribute('tax_class_id', $taxClassId); return $product; } ); } /** * Create a shipping address for our order * * @return AddressInterface */ private function createShippingAddress() { /** @var AddressInterface $address */ $address = $this->addressFactory->create(); $address->setCity('West Chester'); $address->setCountryId('US'); $address->setFirstname('John'); $address->setLastname('Doe'); $address->setPostcode('19382'); $address->setRegion('Pennsylvania'); $address->setRegionCode('PA'); $address->setRegionId(51); $address->setStreet(['233 West Gay St']); $address->setTelephone('1234567890'); return $address; } /** * Create and save our test's needed tax class * * @param string $taxClassName * @return string Tax Class ID * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\LocalizedException */ private function createTaxClass($taxClassName) { return $this->taxClassBuilder->createTaxClass($taxClassName, 'PRODUCT'); } }