Beispiel #1
0
 public function testGetProductWeeeAttributes()
 {
     /** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
     $customerRepository = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\CustomerRepositoryInterface');
     $customerMetadataService = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\CustomerMetadataInterface');
     $customerFactory = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\Data\\CustomerInterfaceFactory', ['metadataService' => $customerMetadataService]);
     $dataObjectHelper = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\DataObjectHelper');
     $expected = $this->_extensibleDataObjectConverter->toFlatArray($customerRepository->getById(1), [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $customerDataSet = $customerFactory->create();
     $dataObjectHelper->populateWithArray($customerDataSet, $expected, '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $fixtureGroupCode = 'custom_group';
     $fixtureTaxClassId = 3;
     /** @var \Magento\Customer\Model\Group $group */
     $group = Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Group');
     $fixtureGroupId = $group->load($fixtureGroupCode, 'customer_group_code')->getId();
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = Bootstrap::getObjectManager()->create('Magento\\Quote\\Model\\Quote');
     $quote->setCustomerGroupId($fixtureGroupId);
     $quote->setCustomerTaxClassId($fixtureTaxClassId);
     $quote->setCustomer($customerDataSet);
     $shipping = new \Magento\Framework\Object(['quote' => $quote]);
     $product = Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $product->load(1);
     $weeeTax = Bootstrap::getObjectManager()->create('Magento\\Weee\\Model\\Tax');
     $weeeTaxData = ['website_id' => '1', 'entity_id' => '1', 'country' => 'US', 'value' => '12.4', 'state' => '0', 'attribute_id' => '73', 'entity_type_id' => '0'];
     $weeeTax->setData($weeeTaxData);
     $weeeTax->save();
     $amount = $this->_model->getProductWeeeAttributes($product, $shipping);
     $this->assertEquals('12.4000', $amount[0]->getAmount());
 }
Beispiel #2
0
 public function testGetProductWeeeAttributes()
 {
     /** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
     $customerRepository = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\CustomerRepositoryInterface');
     $customerMetadataService = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\CustomerMetadataInterface');
     $customerFactory = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\Data\\CustomerInterfaceFactory', ['metadataService' => $customerMetadataService]);
     $dataObjectHelper = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\DataObjectHelper');
     $expected = $this->_extensibleDataObjectConverter->toFlatArray($customerRepository->getById(1), [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $customerDataSet = $customerFactory->create();
     $dataObjectHelper->populateWithArray($customerDataSet, $expected, '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $fixtureGroupCode = 'custom_group';
     $fixtureTaxClassId = 3;
     /** @var \Magento\Customer\Model\Group $group */
     $group = Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Group');
     $fixtureGroupId = $group->load($fixtureGroupCode, 'customer_group_code')->getId();
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = Bootstrap::getObjectManager()->create('Magento\\Quote\\Model\\Quote');
     $quote->setCustomerGroupId($fixtureGroupId);
     $quote->setCustomerTaxClassId($fixtureTaxClassId);
     $quote->setCustomer($customerDataSet);
     $shipping = new \Magento\Framework\DataObject(['quote' => $quote]);
     $productRepository = Bootstrap::getObjectManager()->create('Magento\\Catalog\\Api\\ProductRepositoryInterface');
     $product = $productRepository->get('simple-with-ftp');
     $amount = $this->_model->getProductWeeeAttributes($product, $shipping, null, null, true);
     $this->assertTrue(is_array($amount));
     $this->assertArrayHasKey(0, $amount);
     $this->assertEquals(12.7, $amount[0]->getAmount());
 }
Beispiel #3
0
 public function testGetProductWeeeAttributes()
 {
     $customerAccountService = Bootstrap::getObjectManager()->create('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface');
     $customerMetadataService = Bootstrap::getObjectManager()->create('Magento\\Customer\\Service\\V1\\CustomerMetadataService');
     $customerBuilder = Bootstrap::getObjectManager()->create('Magento\\Customer\\Service\\V1\\Data\\CustomerBuilder', ['metadataService' => $customerMetadataService]);
     $expected = \Magento\Framework\Service\EavDataObjectConverter::toFlatArray($customerAccountService->getCustomer(1));
     $customerBuilder->populateWithArray($expected);
     $customerDataSet = $customerBuilder->create();
     $fixtureGroupCode = 'custom_group';
     $fixtureTaxClassId = 3;
     /** @var \Magento\Customer\Model\Group $group */
     $group = Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Group');
     $fixtureGroupId = $group->load($fixtureGroupCode, 'customer_group_code')->getId();
     /** @var \Magento\Sales\Model\Quote $quote */
     $quote = Bootstrap::getObjectManager()->create('Magento\\Sales\\Model\\Quote');
     $quote->setCustomerGroupId($fixtureGroupId);
     $quote->setCustomerTaxClassId($fixtureTaxClassId);
     $quote->setCustomerData($customerDataSet);
     $shipping = new \Magento\Framework\Object(['quote' => $quote]);
     $product = Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $product->load(1);
     $weeeTax = Bootstrap::getObjectManager()->create('Magento\\Weee\\Model\\Tax');
     $weeeTaxData = array('website_id' => '1', 'entity_id' => '1', 'country' => 'US', 'value' => '12.4', 'state' => '0', 'attribute_id' => '75', 'entity_type_id' => '0');
     $weeeTax->setData($weeeTaxData);
     $weeeTax->save();
     $amount = $this->_model->getProductWeeeAttributes($product, $shipping);
     $this->assertEquals('12.4000', $amount[0]->getAmount());
 }
 /**
  * Exclude WEEE attributes from standard form generation
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     //adminhtml_catalog_product_form_prepare_excluded_field_list
     $block = $observer->getEvent()->getObject();
     $list = $block->getFormExcludedFieldList();
     $attributes = $this->weeeTax->getWeeeAttributeCodes(true);
     $list = array_merge($list, array_values($attributes));
     $block->setFormExcludedFieldList($list);
     return $this;
 }
 /**
  * Assign custom renderer for product create/edit form weee attribute element
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var \Magento\Framework\Data\Form $form */
     $form = $observer->getEvent()->getForm();
     $attributes = $this->weeeTax->getWeeeAttributeCodes(true);
     foreach ($attributes as $code) {
         $weeeTax = $form->getElement($code);
         if ($weeeTax) {
             $weeeTax->setRenderer($this->layout->createBlock('Magento\\Weee\\Block\\Renderer\\Weee\\Tax'));
         }
     }
     return $this;
 }
 /**
  * test GetProductWeeeAttributes
  * @dataProvider getProductWeeeAttributesDataProvider
  * @param array $weeeTaxCalculationsByEntity
  * @param array $expectedFptLabel
  */
 public function testGetProductWeeeAttributes($weeeTaxCalculationsByEntity, $expectedFptLabel)
 {
     $product = $this->getMock('\\Magento\\Catalog\\Model\\Product', [], [], '', false);
     $website = $this->getMock('\\Magento\\Store\\Model\\Website', [], [], '', false);
     $store = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false);
     $group = $this->getMock('\\Magento\\Store\\Model\\Group', [], [], '', false);
     $attribute = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute', [], [], '', false);
     $calculation = $this->getMock('Magento\\Tax\\Model\\Calculation', [], [], '', false);
     $obj = new \Magento\Framework\DataObject(['country' => 'US', 'region' => 'TX']);
     $calculation->expects($this->once())->method('getRateRequest')->willReturn($obj);
     $calculation->expects($this->once())->method('getDefaultRateRequest')->willReturn($obj);
     $calculation->expects($this->any())->method('getRate')->willReturn('10');
     $attribute->expects($this->once())->method('getAttributeCodesByFrontendType')->willReturn(['0' => 'fpt']);
     $store->expects($this->any())->method('getId')->willReturn(1);
     $product->expects($this->any())->method('getId')->willReturn(1);
     $website->expects($this->any())->method('getId')->willReturn(1);
     $website->expects($this->any())->method('getDefaultGroup')->willReturn($group);
     $group->expects($this->any())->method('getDefaultStore')->willReturn($store);
     $this->storeManager->expects($this->any())->method('getWebsite')->willReturn($website);
     $this->weeeConfig->expects($this->any())->method('isEnabled')->willReturn(true);
     $this->weeeConfig->expects($this->any())->method('isTaxable')->willReturn(true);
     $this->attributeFactory->expects($this->any())->method('create')->willReturn($attribute);
     $this->calculationFactory->expects($this->any())->method('create')->willReturn($calculation);
     $this->priceCurrency->expects($this->any())->method('round')->with(0.1)->willReturn(0.25);
     $this->resource->expects($this->any())->method('fetchWeeeTaxCalculationsByEntity')->willReturn([0 => $weeeTaxCalculationsByEntity]);
     $result = $this->model->getProductWeeeAttributes($product, null, null, null, true);
     $this->assertTrue(is_array($result));
     $this->assertArrayHasKey(0, $result);
     $obj = $result[0];
     $this->assertEquals(1, $obj->getAmount());
     $this->assertEquals(0.25, $obj->getTaxAmount());
     $this->assertEquals($weeeTaxCalculationsByEntity['attribute_code'], $obj->getCode());
     $this->assertEquals(__($expectedFptLabel), $obj->getName());
 }
Beispiel #7
0
 public function testGetWeeeAttributesForBundle()
 {
     $prodId1 = 1;
     $prodId2 = 2;
     $fptCode1 = 'fpt' . $prodId1;
     $fptCode2 = 'fpt' . $prodId2;
     $weeeObject1 = new \Magento\Framework\DataObject(['code' => $fptCode1, 'amount' => '15.0000']);
     $weeeObject2 = new \Magento\Framework\DataObject(['code' => $fptCode2, 'amount' => '15.0000']);
     $testArray = [$prodId1 => [$fptCode1 => $weeeObject1], $prodId2 => [$fptCode2 => $weeeObject2]];
     $this->weeeTax->expects($this->any())->method('getProductWeeeAttributes')->will($this->returnValue([$weeeObject1, $weeeObject2]));
     $productSimple = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Type\\Simple', ['getId'], [], '', false);
     $productSimple->expects($this->at(0))->method('getId')->will($this->returnValue($prodId1));
     $productSimple->expects($this->at(1))->method('getId')->will($this->returnValue($prodId2));
     $productInstance = $this->getMock('\\Magento\\Bundle\\Model\\Product\\Type', [], [], '', false);
     $productInstance->expects($this->any())->method('getSelectionsCollection')->will($this->returnValue([$productSimple]));
     $store = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false);
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->getMock('\\Magento\\Bundle\\Model\\Product', ['getTypeInstance', 'getStoreId', 'getStore', 'getTypeId'], [], '', false);
     $product->expects($this->any())->method('getTypeInstance')->will($this->returnValue($productInstance));
     $product->expects($this->any())->method('getStoreId')->will($this->returnValue(1));
     $product->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $product->expects($this->any())->method('getTypeId')->will($this->returnValue('bundle'));
     $registry = $this->getMock('Magento\\Framework\\Registry', [], [], '', false);
     $registry->expects($this->any())->method('registry')->with('current_product')->will($this->returnValue($product));
     $this->assertEquals($testArray, $this->helperData->getWeeeAttributesForBundle($product));
 }
Beispiel #8
0
 /**
  * Returns original amount
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return int
  */
 public function getOriginalAmount($product)
 {
     if ($this->isEnabled()) {
         return $this->_weeeTax->getWeeeAmount($product, null, null, null, false, true);
     }
     return 0;
 }
Beispiel #9
0
    /**
     * @param \Magento\Framework\App\ActionInterface $subject
     * @param callable $proceed
     * @param \Magento\Framework\App\RequestInterface $request
     * @return mixed
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     * @SuppressWarnings(PHPMD.NPathComplexity)
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function aroundExecute(
        \Magento\Framework\App\ActionInterface $subject,
        \Closure $proceed,
        \Magento\Framework\App\RequestInterface $request
    ) {
        if (!$this->weeeHelper->isEnabled() ||
            !$this->customerSession->isLoggedIn() ||
            !$this->moduleManager->isEnabled('Magento_PageCache') ||
            !$this->cacheConfig->isEnabled()) {
            return $proceed($request);
        }

        $basedOn = $this->taxHelper->getTaxBasedOn();
        if ($basedOn != 'shipping' && $basedOn != 'billing') {
            return $proceed($request);
        }

        $weeeTaxRegion = $this->getWeeeTaxRegion($basedOn);
        $websiteId = $this->storeManager->getStore()->getWebsiteId();
        $countryId = $weeeTaxRegion['countryId'];
        $regionId = $weeeTaxRegion['regionId'];

        if (!$countryId && !$regionId) {
            // country and region does not exist
            return $proceed($request);
        } else if ($countryId && !$regionId) {
            // country exist and region does not exist
            $regionId = 0;
            $exist = $this->weeeTax->isWeeeInLocation(
                $countryId,
                $regionId,
                $websiteId
            );
        } else {
            // country and region exist
            $exist = $this->weeeTax->isWeeeInLocation(
                $countryId,
                $regionId,
                $websiteId
            );
            if (!$exist) {
                // just check the country for weee
                $regionId = 0;
                $exist = $this->weeeTax->isWeeeInLocation(
                    $countryId,
                    $regionId,
                    $websiteId
                );
            }
        }

        if ($exist) {
            $this->httpContext->setValue(
                'weee_tax_region',
                ['countryId' => $countryId, 'regionId' => $regionId],
                0
            );
        }
        return $proceed($request);
    }
Beispiel #10
0
 /**
  * Returns amount to display
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return int
  */
 public function getAmountForDisplay($product)
 {
     /** @var \Magento\Store\Model\Store $store */
     $store = $product->getStore();
     if ($this->isEnabled($store)) {
         return $this->_weeeTax->getWeeeAmount($product, null, null, null, $this->typeOfDisplay(1));
     }
     return 0;
 }
Beispiel #11
0
 public function testGetWeeAttributesForBundle()
 {
     $weeObject = new \Magento\Framework\Object(['code' => 'fpt', 'amount' => '15.0000']);
     $testArray = ['fpt' => $weeObject];
     $this->weeeTax->expects($this->any())->method('getProductWeeeAttributes')->will($this->returnValue([$weeObject]));
     $productSimple = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Type\\Simple', [], [], '', false);
     $productInstance = $this->getMock('\\Magento\\Bundle\\Model\\Product\\Type', [], [], '', false);
     $productInstance->expects($this->any())->method('getSelectionsCollection')->will($this->returnValue([$productSimple]));
     $store = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false);
     $product = $this->getMock('\\Magento\\Bundle\\Model\\Product', ['getTypeInstance', 'getStoreId', 'getStore', 'getTypeId'], [], '', false);
     $product->expects($this->any())->method('getTypeInstance')->will($this->returnValue($productInstance));
     $product->expects($this->any())->method('getStoreId')->will($this->returnValue(1));
     $product->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $product->expects($this->any())->method('getTypeId')->will($this->returnValue('bundle'));
     $registry = $this->getMock('Magento\\Framework\\Registry', [], [], '', false);
     $registry->expects($this->any())->method('registry')->with('current_product')->will($this->returnValue($product));
     $this->assertEquals($testArray, $this->_helperData->getWeeAttributesForBundle($product));
 }
 public function testAroundDispatchBasedOnShipping()
 {
     $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(true);
     $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->willReturn(true);
     $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true);
     $this->weeeHelperMock->expects($this->once())->method('isEnabled')->willReturn(true);
     $this->taxHelperMock->expects($this->once())->method('getTaxBasedOn')->willReturn('shipping');
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $storeMock->expects($this->once())->method('getWebsiteId')->willReturn(1);
     $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
     $this->scopeConfigMock->expects($this->at(0))->method('getValue')->with(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null)->willReturn('US');
     $this->scopeConfigMock->expects($this->at(1))->method('getValue')->with(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_REGION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null)->willReturn(0);
     $this->customerSessionMock->expects($this->once())->method('getDefaultTaxShippingAddress')->willReturn(['country_id' => 'US', 'region_id' => 1]);
     $this->weeeTaxMock->expects($this->once())->method('isWeeeInLocation')->with('US', 1, 1)->willReturn(true);
     $this->httpContextMock->expects($this->once())->method('setValue')->with('weee_tax_region', ['countryId' => 'US', 'regionId' => 1], 0);
     $action = $this->objectManager->getObject('Magento\\Framework\\App\\Test\\Unit\\Action\\Stub\\ActionStub');
     $request = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', ['getActionName'], [], '', false);
     $expectedResult = 'expectedResult';
     $proceed = function ($request) use($expectedResult) {
         return $expectedResult;
     };
     $this->contextPlugin->aroundDispatch($action, $proceed, $request);
 }
Beispiel #13
0
 /**
  * Proxy for \Magento\Weee\Model\Tax::getProductWeeeAttributes()
  *
  * @param \Magento\Catalog\Model\Product                $product
  * @param null|false|\Magento\Framework\DataObject      $shipping
  * @param null|false|\Magento\Framework\DataObject      $billing
  * @param Website                                       $website
  * @param bool                                          $calculateTaxes
  * @param bool                                          $round
  * @return \Magento\Framework\DataObject[]
  */
 public function getProductWeeeAttributes($product, $shipping = null, $billing = null, $website = null, $calculateTaxes = false, $round = true)
 {
     return $this->_weeeTax->getProductWeeeAttributes($product, $shipping, $billing, $website, $calculateTaxes, $round);
 }