Пример #1
0
 /**
  * Log page
  *
  * @return \Magento\Backend\Model\View\Result\Page
  */
 public function execute()
 {
     try {
         $taxClass = $this->taxClassRepository->get($this->getRequest()->getParam('id'));
         $this->coreRegistry->register('current_tax_class', $taxClass);
         /** @var Page $pageResult */
         $pageResult = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
         $pageResult->setActiveMenu('ClassyLlama_AvaTax::avatax_tax_classes_' . \strtolower($this->classType));
         $pageResult->getConfig()->getTitle()->prepend(__('Edit ' . \ucfirst(\strtolower($this->classType)) . ' Tax Class'));
         return $pageResult;
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         $this->messageManager->addError(__('We can\'t find this tax class.'));
         /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         return $resultRedirect->setPath('*/*/');
     }
 }
Пример #2
0
 /**
  * Get the AvaTax Tax Code for a product
  *
  * @param int $taxClassId
  * @return string|null
  */
 protected function getAvaTaxTaxCode($taxClassId)
 {
     try {
         $taxClass = $this->taxClassRepository->get($taxClassId);
         return $taxClass->getAvataxCode();
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         return null;
     }
 }
Пример #3
0
 /**
  * Verifies that the tax class model exists and is a customer tax class type.
  *
  * @param int $taxClassId The id of the tax class model to check
  * @param \Magento\Customer\Api\Data\GroupInterface $group The original group parameters
  * @return void
  * @throws InputException Thrown if the tax class model is invalid
  */
 protected function _verifyTaxClassModel($taxClassId, $group)
 {
     try {
         /* @var TaxClassInterface $taxClassData */
         $taxClassData = $this->taxClassRepository->get($taxClassId);
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         throw InputException::invalidFieldValue('taxClassId', $group->getTaxClassId());
     }
     if ($taxClassData->getClassType() !== TaxClassManagementInterface::TYPE_CUSTOMER) {
         throw InputException::invalidFieldValue('taxClassId', $group->getTaxClassId());
     }
 }
 /**
  * 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());
     }
 }