/** * {@inheritdoc} */ public function delete(\Magento\Tax\Api\Data\TaxClassInterface $taxClass) { $taxClassId = $taxClass->getClassId(); try { $this->taxClassResource->delete($taxClass); } catch (CouldNotDeleteException $e) { throw $e; } catch (\Exception $e) { return false; } $this->classModelRegistry->remove($taxClassId); return true; }
/** * {@inheritdoc} */ public function deleteTaxClass($taxClassId) { $taxClassModel = $this->classModelRegistry->retrieve($taxClassId); try { $taxClassModel->delete(); } catch (CouldNotDeleteException $e) { throw $e; } catch (\Exception $e) { return false; } $this->classModelRegistry->remove($taxClassId); return true; }
/** * Test delete Tax class */ public function testDeleteTaxClass() { $taxClassDataObject = $this->taxClassFactory->create(); $taxClassDataObject->setClassName(self::SAMPLE_TAX_CLASS_NAME . uniqid())->setClassType(TaxClassManagementInterface::TYPE_CUSTOMER); $taxClassId = $this->taxClassRepository->save($taxClassDataObject); $this->assertNotNull($taxClassId); //Verify by getting the Data\TaxClassInterface $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '/' . $taxClassId, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'DeleteById']]; $requestData = ['taxClassId' => $taxClassId]; $result = $this->_webApiCall($serviceInfo, $requestData); $this->assertTrue($result); try { $this->taxClassRegistry->remove($taxClassId); $this->taxClassRepository->get($taxClassId); $this->fail("Tax class was not expected to be returned after being deleted."); } catch (NoSuchEntityException $e) { $this->assertEquals('No such entity with class_id = ' . $taxClassId, $e->getMessage()); } }