/** * Creates a collection item that represents a featuretoggle for the features Grid. * * @param FeaturetoggleInterface $featuretoggle Input data for creating the item. * @return \Magento\Framework\Object Collection item that represents a warehouse */ protected function createFeaturetoggleItem(FeaturetoggleInterface $featuretoggle) { $featuretoggleItem = new \Magento\Framework\Object(); $featuretoggleItem->setFeaturetoggleId($featuretoggle->getFeaturetoggleId()); $featuretoggleItem->setName($featuretoggle->getName()); return $featuretoggleItem; }
/** * Creates a collection item that represents a customer for the customer Grid. * * @param CustomerDetails $customerDetail Input data for creating the item. * @return \Magento\Framework\Object Collection item that represents a customer */ protected function createCustomerDetailItem(CustomerDetails $customerDetail) { $customer = $customerDetail->getCustomer(); $customerNameParts = array($customer->getPrefix(), $customer->getFirstname(), $customer->getMiddlename(), $customer->getLastname(), $customer->getSuffix()); $customerItem = new \Magento\Framework\Object(); $customerItem->setId($customer->getId()); $customerItem->setEntityId($customer->getId()); // All parts of the customer name must be displayed in the name column of the grid $customerItem->setName(implode(' ', array_filter($customerNameParts))); $customerItem->setEmail($customer->getEmail()); $customerItem->setWebsiteId($customer->getWebsiteId()); $customerItem->setCreatedAt($customer->getCreatedAt()); $customerItem->setGroupId($customer->getGroupId()); $billingAddress = null; foreach ($customerDetail->getAddresses() as $address) { if ($address->isDefaultBilling()) { $billingAddress = $address; break; } } if ($billingAddress !== null) { $customerItem->setBillingTelephone($billingAddress->getTelephone()); $customerItem->setBillingPostcode($billingAddress->getPostcode()); $customerItem->setBillingCountryId($billingAddress->getCountryId()); $region = is_null($billingAddress->getRegion()) ? '' : $billingAddress->getRegion()->getRegion(); $customerItem->setBillingRegion($region); } return $customerItem; }
/** * @param Product $product * @param null|false|\Magento\Quote\Model\Quote\Address $shipping * @param null|false|\Magento\Quote\Model\Quote\Address $billing * @param Website $website * @param bool $calculateTax * @return \Magento\Framework\Object[] * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function getProductWeeeAttributes($product, $shipping = null, $billing = null, $website = null, $calculateTax = null) { $result = []; $websiteId = $this->_storeManager->getWebsite($website)->getId(); /** @var \Magento\Store\Model\Store $store */ $store = $this->_storeManager->getWebsite($website)->getDefaultGroup()->getDefaultStore(); $allWeee = $this->getWeeeTaxAttributeCodes($store); if (!$allWeee) { return $result; } /** @var \Magento\Tax\Model\Calculation $calculator */ $calculator = $this->_calculationFactory->create(); if ($shipping && $shipping->getCountryId()) { $customerTaxClass = $shipping->getQuote()->getCustomerTaxClassId(); } else { // if customer logged use it default shipping and billing address if ($customerId = $this->_customerSession->getCustomerId()) { $shipping = $this->accountManagement->getDefaultShippingAddress($customerId); $billing = $this->accountManagement->getDefaultBillingAddress($customerId); $customerTaxClass = null; } else { $shippingAddressArray = $this->_customerSession->getDefaultTaxShippingAddress(); $billingAddressArray = $this->_customerSession->getDefaultTaxBillingAddress(); if (!empty($billingAddressArray)) { $billing = new \Magento\Framework\Object($billingAddressArray); } if (!empty($shippingAddressArray)) { $shipping = new \Magento\Framework\Object($shippingAddressArray); } $customerTaxClass = $this->_customerSession->getCustomerTaxClassId(); } } $rateRequest = $calculator->getRateRequest($shipping, $billing, $customerTaxClass, $store); $defaultRateRequest = $calculator->getDefaultRateRequest($store); $productAttributes = $product->getTypeInstance()->getSetAttributes($product); foreach ($productAttributes as $code => $attribute) { if (in_array($code, $allWeee)) { $attributeSelect = $this->getResource()->getReadConnection()->select(); $attributeSelect->from($this->getResource()->getTable('weee_tax'), 'value')->where('attribute_id = ?', (int) $attribute->getId())->where('website_id IN(?)', [$websiteId, 0])->where('country = ?', $rateRequest->getCountryId())->where('state IN(?)', [$rateRequest->getRegionId(), 0])->where('entity_id = ?', (int) $product->getId())->limit(1); $order = ['state ' . \Magento\Framework\DB\Select::SQL_DESC, 'website_id ' . \Magento\Framework\DB\Select::SQL_DESC]; $attributeSelect->order($order); $value = $this->getResource()->getReadConnection()->fetchOne($attributeSelect); if ($value) { $taxAmount = $amount = 0; $amount = $value; if ($calculateTax && $this->weeeConfig->isTaxable($store)) { /** @var \Magento\Tax\Model\Calculation $calculator */ $defaultPercent = $calculator->getRate($defaultRateRequest->setProductClassId($product->getTaxClassId())); $currentPercent = $calculator->getRate($rateRequest->setProductClassId($product->getTaxClassId())); if ($this->_taxData->priceIncludesTax($store)) { $amountInclTax = $value / (100 + $defaultPercent) * (100 + $currentPercent); //round the "golden price" $amountInclTax = $this->priceCurrency->round($amountInclTax); $taxAmount = $amountInclTax - $amountInclTax / (100 + $currentPercent) * 100; $taxAmount = $this->priceCurrency->round($taxAmount); } else { $appliedRates = $this->_calculationFactory->create()->getAppliedRates($rateRequest); if (count($appliedRates) > 1) { $taxAmount = 0; foreach ($appliedRates as $appliedRate) { $taxRate = $appliedRate['percent']; $taxAmount += $this->priceCurrency->round($value * $taxRate / 100); } } else { $taxAmount = $this->priceCurrency->round($value * $currentPercent / 100); } $taxAmount = $this->priceCurrency->round($value * $currentPercent / 100); } } $one = new \Magento\Framework\Object(); $one->setName(__($attribute->getFrontend()->getLabel()))->setAmount($amount)->setTaxAmount($taxAmount)->setCode($attribute->getAttributeCode()); $result[] = $one; } } } return $result; }
public function generatePathDataProvider() { $product = new \Magento\Framework\Object(); $product->setName('test product')->setId(111); $category = new \Magento\Framework\Object(); $category->setName('test category')->setId(999)->setLevel(2)->setUrlPath('test/category')->setParentId(3); return array(array('target', $product, null, null, 'catalog/product/view/id/111'), array('target', null, $category, null, 'catalog/category/view/id/999'), array('id', $product, null, null, 'product/111'), array('id', null, $category, null, 'category/999'), array('request', $product, $category, null, 'test/category/test-product.html'), array('request', null, $category, null, 'category-1/test-category.html')); }