public function testGetAccountPassword() { $storeId = 1; $configPasswordKey = 'password'; $password = '******'; $this->scopeConfig->expects($this->once())->method('getValue')->with('google/googleshopping/' . $configPasswordKey, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)->will($this->returnValue($password)); $this->assertEquals($password, $this->model->getAccountPassword($storeId)); }
/** * Set current attribute to entry (for specified product) * * @param \Magento\Catalog\Model\Product $product * @param \Magento\Framework\Gdata\Gshopping\Entry $entry * @return \Magento\Framework\Gdata\Gshopping\Entry */ public function convertAttribute($product, $entry) { $targetCountry = $this->_config->getTargetCountry($product->getStoreId()); $value = $this->_typeFactory->create()->loadByAttributeSetId($product->getAttributeSetId(), $targetCountry); $val = $value->getCategory() == \Magento\GoogleShopping\Helper\Category::CATEGORY_OTHER ? '' : $value->getCategory(); $this->_setAttribute($entry, 'google_product_category', self::ATTRIBUTE_TYPE_TEXT, htmlspecialchars_decode($val, ENT_NOQUOTES)); return $entry; }
/** * Retrieve option array with allowed countries * * @return array */ public function toOptionArray() { $_allowed = $this->_config->getAllowedCountries(); $result = []; foreach ($_allowed as $iso => $info) { $result[] = ['value' => $iso, 'label' => $info['name']]; } return $result; }
/** * Set current attribute to entry (for specified product) * * @param Product $product * @param Entry $entry * @return Entry */ public function convertAttribute($product, $entry) { $product->setWebsiteId($this->_storeManager->getStore($product->getStoreId())->getWebsiteId()); $defaultCustomerGroup = $this->_customerGroupService->getDefaultGroup($product->getStoreId()); $product->setCustomerGroupId($defaultCustomerGroup->getId()); /** @var \Magento\Store\Model\Store $store */ $store = $this->_storeManager->getStore($product->getStoreId()); $isSalePriceAllowed = $this->_config->getTargetCountry($product->getStoreId()) == 'US'; // get tax settings $priceDisplayType = $this->_taxData->getPriceDisplayType($product->getStoreId()); $inclTax = $priceDisplayType == Config::DISPLAY_TYPE_INCLUDING_TAX; $finalPrice = $this->_getFinalPrice($product, $store, $inclTax, $isSalePriceAllowed); // calculate price attribute value $price = $this->_getPrice($product, $store, $priceDisplayType, $inclTax, $isSalePriceAllowed); if ($isSalePriceAllowed) { // set sale_price and effective dates for it if ($price && $price - $finalPrice > 0.0001) { $this->_setAttributePrice($entry, $product, $price); $this->_setAttributePrice($entry, $product, $finalPrice, 'sale_price'); $this->_setEffectiveDate($product, $entry); } else { $this->_setAttributePrice($entry, $product, $finalPrice); $entry->removeContentAttribute('sale_price_effective_date'); $entry->removeContentAttribute('sale_price'); } // calculate taxes $tax = $this->getGroupAttributeTax(); if (!$inclTax && !is_null($tax)) { $tax->convertAttribute($product, $entry); } } else { $this->_setAttributePrice($entry, $product, $price); } return $entry; }
/** * Set current attribute to entry (for specified product) * * @param \Magento\Catalog\Model\Product $product * @param \Magento\Framework\Gdata\Gshopping\Entry $entry * @return \Magento\Framework\Gdata\Gshopping\Entry */ public function convertAttribute($product, $entry) { $entry->cleanTaxes(); if ($this->_taxData->getConfig()->priceIncludesTax()) { return $entry; } $calc = $this->calculation; $customerTaxClass = $calc->getDefaultCustomerTaxClass($product->getStoreId()); $rates = $calc->getRatesByCustomerAndProductTaxClasses($customerTaxClass, $product->getTaxClassId()); $targetCountry = $this->_config->getTargetCountry($product->getStoreId()); $ratesTotal = 0; foreach ($rates as $rate) { if ($targetCountry == $rate['country']) { $regions = $this->_parseRegions($rate['state'], $rate['postcode']); $ratesTotal += count($regions); if ($ratesTotal > self::RATES_MAX) { throw new \Magento\Framework\Model\Exception(__("Google shopping only supports %1 tax rates per product", self::RATES_MAX)); } foreach ($regions as $region) { $entry->addTax(array('tax_rate' => $rate['value'] * 100, 'tax_country' => empty($rate['country']) ? '*' : $rate['country'], 'tax_region' => $region)); } } } return $entry; }
/** * Get allowed country names array * * @return array */ protected function _getCountriesArray() { $_allowed = $this->_config->getAllowedCountries(); $result = []; foreach ($_allowed as $iso => $info) { $result[$iso] = $info['name']; } return $result; }
/** * Append to attributes array subattribute's models * * @param array $attributes * @return array */ protected function _initGroupAttributes($attributes) { $group = $this->_config->getAttributeGroupsFlat(); foreach ($group as $child => $parent) { if (isset($attributes[$parent]) && !isset($attributes[$parent]['group_attribute_' . $child])) { $attributes[$parent]->addData(['group_attribute_' . $child => $this->_attributeFactory->createAttribute($child)]); } } return $attributes; }
/** * Build HTML code for select element which contains all available Google's attributes * * @return string */ public function getGcontentAttributesSelectHtml() { $options[] = ['label' => __('Custom attribute, no mapping')]; $attributesTree = $this->_config->getAttributesByCountry($this->getTargetCountry()); foreach ($attributesTree as $destination => $attributes) { $options[] = ['label' => $destination, 'is_group' => true]; foreach ($attributes as $attribute => $params) { $options[$attribute] = ['label' => $params['name']]; if ((int) $params['required'] == 1) { $options[$attribute]['style'] = 'color: #940000;'; } } $options[] = ['is_group' => true, 'is_close' => true]; } $select = $this->getLayout()->createBlock('Magento\\GoogleShopping\\Block\\Adminhtml\\Types\\Edit\\Select')->setId($this->getFieldId() . '_{{index}}_gattribute')->setName($this->getFieldName() . '[{{index}}][gcontent_attribute]')->setOptions($options); return $this->_toOneLineString($select->toHtml()); }
/** * Set current attribute to entry (for specified product) * * @param \Magento\Catalog\Model\Product $product * @param \Magento\Framework\Gdata\Gshopping\Entry $entry * @return \Magento\Framework\Gdata\Gshopping\Entry * @throws \Magento\Framework\Exception\LocalizedException */ public function convertAttribute($product, $entry) { $entry->cleanTaxes(); if ($this->_taxData->getConfig()->priceIncludesTax()) { return $entry; } $defaultCustomerTaxClassId = $this->_getDefaultCustomerTaxClassId($product->getStoreId()); $rates = $this->_taxRateManagement->getRatesByCustomerAndProductTaxClassId($defaultCustomerTaxClassId, $product->getTaxClassId()); $targetCountry = $this->_config->getTargetCountry($product->getStoreId()); $ratesTotal = 0; foreach ($rates as $rate) { $countryId = $rate->getTaxCountryId(); $postcode = $rate->getTaxPostcode(); if ($targetCountry == $countryId) { $regions = $this->_getRegionsByRegionId($rate->getTaxRegionId(), $postcode); $ratesTotal += count($regions); if ($ratesTotal > self::RATES_MAX) { throw new \Magento\Framework\Exception\LocalizedException(__('Google shopping only supports %1 tax rates per product', self::RATES_MAX)); } foreach ($regions as $region) { $adjustments = $product->getPriceInfo()->getAdjustments(); if (array_key_exists('tax', $adjustments)) { $taxIncluded = true; } else { $taxIncluded = false; } $quoteDetailsItemDataArray = ['code' => $product->getSku(), 'type' => 'product', 'tax_class_key' => [TaxClassKeyInterface::KEY_TYPE => TaxClassKeyInterface::TYPE_ID, TaxClassKeyInterface::KEY_VALUE => $product->getTaxClassId()], 'unit_price' => $product->getPrice(), 'quantity' => 1, 'tax_included' => $taxIncluded, 'short_description' => $product->getName()]; $billingAddressDataArray = ['country_id' => $countryId, 'region' => ['region_id' => $rate->getTaxRegionId()], 'postcode' => $postcode]; $shippingAddressDataArray = ['country_id' => $countryId, 'region' => ['region_id' => $rate->getTaxRegionId()], 'postcode' => $postcode]; $quoteDetailsDataArray = ['billing_address' => $billingAddressDataArray, 'shipping_address' => $shippingAddressDataArray, 'customer_tax_class_key' => [TaxClassKeyInterface::KEY_TYPE => TaxClassKeyInterface::TYPE_ID, TaxClassKeyInterface::KEY_VALUE => $defaultCustomerTaxClassId], 'items' => [$quoteDetailsItemDataArray]]; $quoteDetailsObject = $this->_quoteDetailsFactory->create(); $this->dataObjectHelper->populateWithArray($quoteDetailsObject, $quoteDetailsDataArray, '\\Magento\\Tax\\Api\\Data\\QuoteDetailsInterface'); $taxDetails = $this->_taxCalculationService->calculateTax($quoteDetailsObject, $product->getStoreId()); $taxRate = $taxDetails->getTaxAmount() / $taxDetails->getSubtotal() * 100; $entry->addTax(['tax_rate' => $taxRate, 'tax_country' => $countryId, 'tax_region' => $region]); } } } return $entry; }
/** * Set current attribute to entry (for specified product) * * @param \Magento\Catalog\Model\Product $product * @param \Magento\Framework\Gdata\Gshopping\Entry $entry * @return \Magento\Framework\Gdata\Gshopping\Entry */ public function convertAttribute($product, $entry) { $targetCountry = $this->_config->getTargetCountry($product->getStoreId()); $value = $this->_config->getCountryInfo($targetCountry, 'language', $product->getStoreId()); return $this->_setAttribute($entry, 'content_language', self::ATTRIBUTE_TYPE_TEXT, $value); }
/** * Target Country * * @return string Two-letters country ISO code */ public function getTargetCountry() { return $this->_config->getTargetCountry($this->getStoreId()); }
public function testToHtmlWithoutContent() { $this->_config->expects($this->once())->method('getConfigData')->with('verify_meta_tag')->will($this->returnValue('')); $this->assertEquals('', $this->_block->toHtml()); }
/** * Set current attribute to entry (for specified product) * * @param \Magento\Catalog\Model\Product $product * @param \Magento\Framework\Gdata\Gshopping\Entry $entry * @return \Magento\Framework\Gdata\Gshopping\Entry */ public function convertAttribute($product, $entry) { $destInfo = $this->_config->getDestinationsInfo($product->getStoreId()); $entry->setDestinationsMode($destInfo); return $entry; }
/** * Set current attribute to entry (for specified product) * * @param \Magento\Catalog\Model\Product $product * @param \Magento\Framework\Gdata\Gshopping\Entry $entry * @return \Magento\Framework\Gdata\Gshopping\Entry */ public function convertAttribute($product, $entry) { $value = $this->_config->getTargetCountry($product->getStoreId()); return $this->_setAttribute($entry, 'target_country', self::ATTRIBUTE_TYPE_TEXT, $value); }
/** * {@inheritdoc} * * @return string */ protected function _toHtml() { return ($content = $this->_config->getConfigData('verify_meta_tag')) ? '<meta name="google-site-verification" content="' . $this->escapeHtml($content) . '"/>' : ''; }
/** * Renders Google Content Item Id * * @param \Magento\Framework\Object $row * @return string */ public function render(\Magento\Framework\Object $row) { $iso = $row->getData($this->getColumn()->getIndex()); return $this->_config->getCountryInfo($iso, 'name'); }