public function testGetFormats() { $this->_storeMock->expects($this->once())->method('getId'); $this->_scopeConfigMock->expects($this->any())->method('getValue')->will($this->returnValue('someValue')); $rendererMock = $this->getMock('Magento\\Framework\\Object'); $this->_addressHelperMock->expects($this->any())->method('getRenderer')->will($this->returnValue($rendererMock)); $firstExpected = new \Magento\Framework\Object(); $firstExpected->setCode('format_one')->setTitle('format_one_title')->setDefaultFormat('someValue')->setEscapeHtml(false)->setRenderer(null); $secondExpected = new \Magento\Framework\Object(); $secondExpected->setCode('format_two')->setTitle('format_two_title')->setDefaultFormat('someValue')->setEscapeHtml(true)->setRenderer(null); $expectedResult = [$firstExpected, $secondExpected]; $this->assertEquals($expectedResult, $this->_model->getFormats()); }
/** * Creates a collection item that represents a tax rule for the tax rules grid. * * @param TaxRuleInterface $taxRule Input data for creating the item. * @return \Magento\Framework\Object Collection item that represents a tax rule */ protected function createTaxRuleCollectionItem(TaxRuleInterface $taxRule) { $collectionItem = new \Magento\Framework\Object(); $collectionItem->setTaxCalculationRuleId($taxRule->getId()); $collectionItem->setCode($taxRule->getCode()); /* should cast to string so that some optional fields won't be null on the collection grid pages */ $collectionItem->setPriority((string) $taxRule->getPriority()); $collectionItem->setPosition((string) $taxRule->getPosition()); $collectionItem->setCalculateSubtotal($taxRule->getCalculateSubtotal() ? '1' : '0'); $collectionItem->setCustomerTaxClasses($taxRule->getCustomerTaxClassIds()); $collectionItem->setProductTaxClasses($taxRule->getProductTaxClassIds()); $collectionItem->setTaxRates($taxRule->getTaxRateIds()); return $collectionItem; }
/** * Creates a collection item that represents a tax rate for the tax rates grid. * * @param TaxRate $taxRate Input data for creating the item. * @return \Magento\Framework\Object Collection item that represents a tax rate */ protected function createTaxRateCollectionItem(TaxRate $taxRate) { $collectionItem = new \Magento\Framework\Object(); $collectionItem->setTaxCalculationRateId($taxRate->getId()); $collectionItem->setCode($taxRate->getCode()); $collectionItem->setTaxCountryId($taxRate->getTaxCountryId()); $collectionItem->setTaxRegionId($taxRate->getTaxRegionId()); $collectionItem->setRegionName($taxRate->getRegionName()); $collectionItem->setTaxPostcode($taxRate->getTaxPostcode()); $collectionItem->setRate($taxRate->getRate()); $collectionItem->setTitles($this->rateConverter->createTitleArrayFromServiceObject($taxRate)); if ($taxRate->getZipTo() != null && $taxRate->getZipFrom() != null) { /* must be a "1" for existing code (e.g. JavaScript) to work */ $collectionItem->setZipIsRange("1"); $collectionItem->setZipFrom($taxRate->getZipFrom()); $collectionItem->setZipTo($taxRate->getZipTo()); } else { $collectionItem->setZipIsRange(null); $collectionItem->setZipFrom(null); $collectionItem->setZipTo(null); } return $collectionItem; }
/** * Retrieve address formats * * @return array */ public function getFormats() { $store = $this->getStore(); $storeId = $store->getId(); if (!isset($this->_types[$storeId])) { $this->_types[$storeId] = []; foreach ($this->get() as $typeCode => $typeConfig) { $path = sprintf('%s%s', self::XML_PATH_ADDRESS_TEMPLATE, $typeCode); $type = new \Magento\Framework\Object(); if (isset($typeConfig['escapeHtml']) && ($typeConfig['escapeHtml'] == 'true' || $typeConfig['escapeHtml'] == '1')) { $escapeHtml = true; } else { $escapeHtml = false; } $type->setCode($typeCode)->setTitle((string) $typeConfig['title'])->setDefaultFormat($this->_scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store))->setEscapeHtml($escapeHtml); $renderer = isset($typeConfig['renderer']) ? (string) $typeConfig['renderer'] : null; if (!$renderer) { $renderer = self::DEFAULT_ADDRESS_RENDERER; } $type->setRenderer($this->_addressHelper->getRenderer($renderer)->setType($type)); $this->_types[$storeId][] = $type; } } return $this->_types[$storeId]; }