/** * CMS block cache, must use the block id from the database * * @param type $block */ public function applyCmsBlock($block) { // The "messages" block is session-dependent, don't cache if (Mage::helper('cache')->responseHasMessages()) { $block->setData('cache_lifetime', null); return; } // Set cache tags $tags = array(); $blockId = $block->getData('block_id'); if ($blockId) { $cmsBlock = Mage::getModel('cms/block')->setStoreId(Mage::app()->getStore()->getId())->load($blockId); if ($cmsBlock->getIsActive()) { $tags = $block->getCacheTags(); $tags[] = Mage_Cms_Model_Block::CACHE_TAG . '_' . $cmsBlock->getId(); } } $block->setData('cache_tags', $tags); // Set cache key $keys = $block->getCacheKeys(); $blockId = $block->getData('block_id'); if ($blockId) { $cmsBlock = Mage::getModel('cms/block')->setStoreId(Mage::app()->getStore()->getId())->load($blockId); if ($cmsBlock->getIsActive()) { $keys = $block->getCacheKeyInfo(); if (!is_array($keys)) { $keys = array(); } $keys[] = $blockId; $keys[] = $block->getLayout()->getUpdate()->getCacheId(); } } $block->setData('cache_keys', $keys); }
/** * Saves form data, including document saving * @param type $form * @return JsonResponse */ public function saveData($form) { if ($form->isValid()) { $data = $form->getData(); try { $em = $this->getDoctrine()->getManager(); // Subo el fichero y luego lo guardo $data->upload(); $em->persist($data); $em->flush(); $response['success'] = true; } catch (\Exception $e) { $response['success'] = false; $response['cause'] = $e->getMessage(); } } else { $response['success'] = false; $response['cause'] = $form->getErrorsAsString(); } return new JsonResponse($response); }
/** * Set tier price * * @param type $product * * @return Innoexts_StorePricing_Helper_Catalog_Product_Price */ public function setTierPrice($product) { $attribute = $this->getTierPriceAttribute(); if (!$attribute) { return $this; } $backend = $attribute->getBackend(); if (!$backend) { return $this; } $helper = $this->getStorePricingHelper(); $store = $helper->getCurrentStore(); $isEditMode = $product->getData('_edit_mode'); $websiteId = null; $storeId = null; if ($this->isGlobalScope()) { $websiteId = null; $storeId = null; } else { if ($this->isWebsiteScope() && $store->getId()) { $websiteId = $store->getWebsiteId(); $storeId = null; } else { if ($this->isStoreScope() && $store->getId()) { $websiteId = $store->getWebsiteId(); $storeId = $store->getId(); } } } $typeId = $product->getTypeId(); $tierPrices = $product->getTierPrices(); if (!empty($tierPrices) && !$isEditMode) { $tierPrices = $backend->preparePriceData2($tierPrices, $typeId, $websiteId, $storeId); } $product->setFinalPrice(null); $product->setData('tier_price', $tierPrices); return $this; }
/** * * @param type $order * @param type $origData */ public function syncOrder($order = false, $debug = false) { // get order item collection $orderItems = $order->getItemsCollection(); if ($debug) { echo '<h4>Inserting ' . count($orderItems) . ' order lines</h4>'; } $ii = 0; foreach ($orderItems as $i => $line) { if ($debug) { echo "<strong>Order Line {$i}</strong><table border='1' style='background-color:#eee'>"; } $_product = Mage::getModel('catalog/product')->load($line->product_id); // $_categories = $_product->getCategoryIds(); // var_dump($line->getData());var_dump($_product->getData()); // File Name........ Z1OB4SSOL // Library........ ID2662AFLV // Format Descr..... // Format Name...... Z1B4SSOL // File Type........ PF Unique Keys - N // Field Name FMT Start Lngth Dec Key Field Description // var_dump($line->getData());die; $data = array('OLTORN' => $order->getId(), 'OLLIN6' => $ii++, 'OLSROM' => 'B4S', 'OLPRDC' => $_product->getData('sku'), 'OLUNIT' => 'CS', 'OLQT15' => round($line->getData('qty_ordered'), 0), 'OLSALP' => round($line->getData('base_price'), 2), 'OLFOCC' => 'N', 'OLDELT' => '0', 'OLRDDT' => '0', 'OLTDCD' => 'N', 'OLDDCD' => 'N', 'OLFICC' => 'N', 'OLBALC' => 'N', 'OLCOSP' => '0', 'OLDSPC' => 'N', 'OLCONO' => '0', 'OLSTRU' => '0', 'OLGWGT' => round($line->getData('weight'), 0), 'OLNWGT' => '0', 'OLGVOL' => '0', 'OLNVOL' => '0', 'OLCONV' => '0', 'OLTXKY' => '0', 'OLWTKY' => '0', 'OLFOCO' => '0', 'OLGDSQ' => '0', 'OLTAM1' => round($line->getData('tax_amount'), 2)); $this->tr('structured insert data', $data, $debug); Mage::getModel('idpas400/db')->insert_row($data, 'Z1OB4SSOL', $debug); if ($debug) { echo '</table>'; } } // File Name........ Z1OB4SSOH // Library........ ID2662AFB4 // Format Descr..... // Format Name...... Z1B4SSOH // File Type........ PF Unique Keys - N // Field Name FMT Start Lngth Dec Key Field Description if ($debug) { echo '<h4>Inserting order header</h4><table border="1" style="background-color:#e1e1e1">'; } $data = array('OHTORN' => $order->getId(), 'OHCRED' => date('Ymd', strtotime($order->getData('created_at'))), 'OHCRTM' => date('His', strtotime($order->getData('created_at'))), 'OHUSER' => 'B4SUSER', 'OHCUNO' => $order->getData('customer_id'), 'OHORDT' => 'B4', 'OHSALE' => 'ASA', 'OHHAND' => 'ASA', 'OHSROM' => 'B4S', 'OHPCUR' => $order->getData('order_currency_code'), 'OHNAME' => $order->getData('customer_firstname') . ' ' . $order->getData('customer_lastname'), 'OHODAT' => date('Ymd', strtotime($order->getData('created_at'))), 'OHDANO' => '00', 'OHCANO' => '00', 'OHICNO' => $order->getData('customer_id'), 'OHCOPE' => $order->hasData('po_number') ? $order->getData('po_number') : is_object($order->getQuote()) ? $order->getQuote()->getData('po_number') : 0, 'OHINCO' => '00', 'OHLANG' => 'EN', 'OHTAXC' => 'N', 'OHBALC' => 'N', 'OHPINC' => 'N', 'OHMINC' => 'N', 'OHHORD' => 'N', 'OHCDAY' => '000', 'OHTODC' => 'NA', 'OHMOTC' => 'UPG', 'OHFREF' => $order->getData('shipping_amount') + $order->getData('shipping_tax_amount'), 'OHPOSF' => '0', 'OHINSF' => '0', 'OHADMF' => '0', 'OHINVF' => '0', 'OHOREF' => $order->getIncrementId(), 'OHHINV' => 'N', 'OHIORD' => 'N', 'OHEANO' => '000', 'OHIANO' => '000', 'OHWOCD' => 'Y', 'OHCONF' => 'Y', 'OHCIDE' => $order->getData('remote_ip'), 'O1NAME' => $order->getShippingAddress()->getData('firstname') . ' ' . $order->getShippingAddress()->getData('lastname'), 'O1ADR1' => $order->getShippingAddress()->getData('street'), 'O1ADR2' => $order->getShippingAddress()->getData('company'), 'O1ADR3' => 'Telephone: ' . $order->getShippingAddress()->getData('telephone'), 'O1ADR4' => $order->getShippingAddress()->getData('city'), 'O1POCD' => $order->getShippingAddress()->getData('postcode'), 'O1CNTY' => '', 'O1SPCD' => $this->convert_state($order->getShippingAddress()->getData('region')), 'O1COUN' => $order->getShippingAddress()->getData('country_id'), 'O1MAIL' => $order->getShippingAddress()->getData('email'), 'O2NAME' => '', 'O2ADR1' => '', 'O2ADR2' => '', 'O2ADR3' => '', 'O2ADR4' => '', 'O2POCD' => '', 'O2CNTY' => '', 'O2SPCD' => '', 'O2COUN' => '', 'O2MAIL' => '', 'O3NAME' => '', 'O3ADR1' => '', 'O3ADR2' => '', 'O3ADR3' => '', 'O3ADR4' => '', 'O3POCD' => '', 'O3CNTY' => '', 'O3SPCD' => '', 'O3COUN' => '', 'O3MAIL' => '', 'O4NAME' => '', 'O4ADR1' => '', 'O4ADR2' => '', 'O4ADR3' => '', 'O4ADR4' => '', 'O4POCD' => '', 'O4CNTY' => '', 'O4SPCD' => '', 'O4COUN' => '', 'OHERCD' => '', 'OHMODU' => 'NETSTORE', 'OHAUTF' => 'N', 'OHOFRU' => '1', 'OHCMPD' => 'N', 'OHMAIL' => $order->getData('customer_email'), 'OHPCDT' => date('Ymd', strtotime($order->getData('created_at'))), 'OHTAM1' => $order->getData('tax_amount')); $this->tr('structured insert data', $data, $debug); Mage::getModel('idpas400/db')->insert_row($data, 'Z1OB4SSOH', $debug); if ($debug) { echo '</table>'; } }
/** * @desc Create invoice * @param type $order * @param type $response * @return type */ public function createInvoice($order, $response) { $payment = $order->getPayment()->getMethodInstance(); $pspReference = trim($response->getData('pspReference')); $success = trim($response->getData('success')); $eventCode = trim($response->getData('eventCode')); $reason = trim($response->getData('reason')); $invoiceAutoMail = (bool) $this->_getConfigData('send_invoice_update_mail'); $_mail = (bool) $this->_getConfigData('send_update_mail'); //create invoice if (strcmp($order->getState(), Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW) == 0) { $order->setState(Mage_Sales_Model_Order::STATE_NEW); } //capture mode if (!$this->isAutoCapture($response, $order)) { $order->addStatusHistoryComment(Mage::helper('adyen')->__('Capture Mode set to Manual')); $order->sendOrderUpdateEmail($_mail); $order->save(); return false; } //$order->addStatusHistoryComment(Mage::helper('adyen')->__('Adyen Payment Successfully completed'), $status); if ($order->canInvoice()) { $invoice = $order->prepareInvoice(); $invoice->getOrder()->setIsInProcess(true); // set transaction id so you can do a online refund this is used instead of online capture // because it is already auto capture in Adyen Backoffice $invoice->setTransactionId(1); $invoice->register()->pay(); try { Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder())->save(); } catch (Exception $e) { $payment->writeLog($e->getMessage()); } //selected adyen status $this->setPaymentAuthorized($order, $success, $response); if ($invoiceAutoMail) { $invoice->sendEmail(); } } $order->sendOrderUpdateEmail($_mail); $order->save(); }
/** * Merge data attributes between $this and $page. * Merging result is stored into $this and $this must be also returned * * Merging is performed only upon pages' data storage * * @param type $page */ public function merge($page) { // merge $this <- $page //if ($this->loadingState < $page->loadingState) { $this->_mergeData($page->getData()); $this->loadingState = $page->loadingState; if ($page->loadingState == self::CUSTOM) { $this->_mergeLoadedGroups($page->getLoadedGroups()); } //} return $this; }
/** * Builds request for DeliverInvoice for Invoice and PaymentPlan payment. * Calls from Magento Capture * * @param type $invoice * @param type $auth * @param type $sveaOrderId * @return type */ public function getDeliverInvoiceRequest($invoice, $auth, $sveaOrderId) { $conf = new SveaMageConfigProvider($auth); $sveaObject = WebPay::deliverOrder($conf); $order = $invoice->getOrder(); $countryCode = $order->getBillingAddress()->getCountryId(); $storeId = $order->getStoreId(); $store = Mage::app()->getStore($storeId); $taxCalculationModel = Mage::getSingleton('tax/calculation'); $taxConfig = Mage::getSingleton('tax/config'); // Add invoiced items foreach ($invoice->getAllItems() as $item) { $orderItem = $item->getOrderItem(); if ($orderItem->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) { continue; } // Default to the item price $name = $item->getName(); $price = $orderItem->getPrice(); $priceInclTax = $orderItem->getPriceInclTax(); $taxPercent = $orderItem->getTaxPercent(); if (!(int) $taxPercent) { $taxPercent = false; } $parentItem = $orderItem->getParentItem(); if ($parentItem) { switch ($parentItem->getProductType()) { case Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE: $price = $parentItem->getPrice(); $priceInclTax = $parentItem->getPriceInclTax(); $taxPercent = $parentItem->getTaxPercent(); break; case Mage_Catalog_Model_Product_Type::TYPE_BUNDLE: $taxPercent = $priceInclTax = $price = 0; $name = '- ' . $name; break; } } if ($taxPercent === false) { // If it's a bundle item we have to calculate the tax from // the including/excluding tax values $taxPercent = round(100 * ($priceInclTax / $price - 1)); } switch (get_class($item)) { case 'Mage_Sales_Model_Quote_Item': case 'Mage_Sales_Model_Order_Invoice_Item': case 'Mage_Sales_Model_Order_Creditmemo_Item': $qty = $item->getQty(); break; default: $qty = $item->getQtyOrdered(); break; } $orderRow = WebPayItem::orderRow()->setArticleNumber($item->getSku())->setQuantity((int) $qty)->setName($name)->setUnit(Mage::helper('svea_webpay')->__('unit'))->setVatPercent((int) $taxPercent); if ($taxConfig->priceIncludesTax($storeId)) { $orderRow->setAmountIncVat((double) $priceInclTax); } else { $orderRow->setAmountExVat((double) $price); } $sveaObject->addOrderRow($orderRow); } $request = $taxCalculationModel->getRateRequest($order->getShippingAddress(), $order->getBillingAddress(), null, $store); // Add shipping fee if ($invoice->getShippingAmount() > 0) { $shippingFee = WebPayItem::shippingFee()->setUnit(Mage::helper('svea_webpay')->__('unit'))->setName($order->getShippingDescription()); // We require shipping tax to be set $shippingTaxClass = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, $storeId); $rate = $taxCalculationModel->getRate($request->setProductClassId($shippingTaxClass)); $shippingFee->setVatPercent((int) $rate); if ($taxConfig->shippingPriceIncludesTax($storeId)) { $shippingFee->setAmountIncVat($invoice->getShippingInclTax()); } else { $shippingFee->setAmountExVat($invoice->getShippingAmount()); } $sveaObject->addFee($shippingFee); } // Possible discount $discount = abs($invoice->getDiscountAmount()); if ($discount) { $discountRow = WebPayItem::fixedDiscount()->setAmountIncVat($discount)->setName(Mage::helper('svea_webpay')->__('discount'))->setUnit(Mage::helper('svea_webpay')->__('unit')); $sveaObject->addDiscount($discountRow); } // Gift card(s) if (abs($order->getGiftCardsAmount())) { $giftCardRow = WebPayItem::fixedDiscount()->setAmountIncVat(abs($order->getGiftCardsAmount()))->setUnit(Mage::helper('svea_webpay')->__('unit')); $sveaObject->addDiscount($giftCardRow); } // Invoice fee $paymentFee = $invoice->getSveaPaymentFeeAmount(); $paymentFeeInclTax = $invoice->getSveaPaymentFeeInclTax(); $invoiced = $invoice->getOrder()->getSveaPaymentFeeInvoiced(); if ($paymentFee > 0 && $invoiced == 0) { $invoiceFee = WebPayItem::invoiceFee()->setUnit(Mage::helper('svea_webpay')->__('unit'))->setName(Mage::helper('svea_webpay')->__('invoice_fee'))->setAmountExVat($paymentFee)->setAmountIncVat($paymentFeeInclTax); $sveaObject->addFee($invoiceFee); $invoice->getOrder()->setSveaPaymentFeeInvoiced($paymentFeeInclTax); } $sveaObject = $sveaObject->setCountryCode($countryCode)->setOrderId($sveaOrderId)->setInvoiceDistributionType(Mage::getStoreConfig("payment/svea_invoice/deliver_method")); $invoice->setData('svea_deliver_request', $sveaObject); return $invoice->getData('svea_deliver_request'); }
/** * Create the encoded string * @param type $Object * @param type $Values * @param type $Format */ public function drawSplitPath($Object,$Values,$Format="") { $this->pChartObject = $Object; $Spacing = isset($Format["Spacing"]) ? $Format["Spacing"] : 20; $TextPadding = isset($Format["TextPadding"]) ? $Format["TextPadding"] : 2; $TextPos = isset($Format["TextPos"]) ? $Format["TextPos"] : TEXT_POS_TOP; $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : null; $Force = isset($Format["Force"]) ? $Format["Force"] : 70; $Segments = isset($Format["Segments"]) ? $Format["Segments"] : 15; $FontSize = $Object->FontSize; $X1 = $Object->GraphAreaX1; $Y1 = $Object->GraphAreaY1; $X2 = $Object->GraphAreaX2; $Y2 = $Object->GraphAreaY2; /* Data Processing */ $Data = $Values->getData(); $Palette = $Values->getPalette(); $LabelSerie = $Data["Abscissa"]; $DataSerie = ""; foreach($Data["Series"] as $SerieName => $Value) { if ( $SerieName != $LabelSerie && $DataSerie == "" ) { $DataSerie = $SerieName; } } $DataSerieSum = array_sum($Data["Series"][$DataSerie]["Data"]); $DataSerieCount = count($Data["Series"][$DataSerie]["Data"]); /* Scale Processing */ if ( $TextPos == TEXT_POS_RIGHT ) { $YScale = (($Y2-$Y1) - (($DataSerieCount+1)*$Spacing)) / $DataSerieSum; } else { $YScale = (($Y2-$Y1) - ($DataSerieCount*$Spacing)) / $DataSerieSum; } $LeftHeight = $DataSerieSum * $YScale; /* Re-compute graph width depending of the text mode choosen */ if ( $TextPos == TEXT_POS_RIGHT ) { $MaxWidth = 0; foreach($Data["Series"][$LabelSerie]["Data"] as $Key => $Label) { $Boundardies = $Object->getTextBox(0,0,$Object->FontName,$Object->FontSize,0,$Label); if ( $Boundardies[1]["X"] > $MaxWidth ) { $MaxWidth = $Boundardies[1]["X"] + $TextPadding*2; } } $X2 = $X2 - $MaxWidth; } /* Drawing */ $LeftY = ((($Y2-$Y1) / 2) + $Y1) - ($LeftHeight/2); $RightY = $Y1; $VectorX = (($X2-$X1) / 2); foreach($Data["Series"][$DataSerie]["Data"] as $Key => $Value) { if ( isset($Data["Series"][$LabelSerie]["Data"][$Key]) ) { $Label = $Data["Series"][$LabelSerie]["Data"][$Key]; } else { $Label = "-"; } $LeftY1 = $LeftY; $LeftY2 = $LeftY + $Value * $YScale; $RightY1 = $RightY + $Spacing; $RightY2 = $RightY + $Spacing + $Value * $YScale; $Settings = array( "R"=>$Palette[$Key]["R"], "G"=>$Palette[$Key]["G"], "B"=>$Palette[$Key]["B"], "Alpha"=>$Palette[$Key]["Alpha"], "NoDraw"=>true, "Segments"=>$Segments, "Surrounding"=>$Surrounding ); $PolyGon = ""; $Angle = $Object->getAngle($X2,$RightY1,$X1,$LeftY1); $VectorX1 = cos(deg2rad($Angle+90)) * $Force + ($X2-$X1)/2 + $X1; $VectorY1 = sin(deg2rad($Angle+90)) * $Force + ($RightY1-$LeftY1)/2 + $LeftY1; $VectorX2 = cos(deg2rad($Angle-90)) * $Force + ($X2-$X1)/2 + $X1; $VectorY2 = sin(deg2rad($Angle-90)) * $Force + ($RightY1-$LeftY1)/2 + $LeftY1; $Points = $Object->drawBezier($X1,$LeftY1,$X2,$RightY1,$VectorX1,$VectorY1,$VectorX2,$VectorY2,$Settings); foreach($Points as $Key => $Pos) { $PolyGon[] = $Pos["X"]; $PolyGon[] = $Pos["Y"]; } $Angle = $Object->getAngle($X2,$RightY2,$X1,$LeftY2); $VectorX1 = cos(deg2rad($Angle+90)) * $Force + ($X2-$X1)/2 +$X1; $VectorY1 = sin(deg2rad($Angle+90)) * $Force + ($RightY2-$LeftY2)/2 + $LeftY2; $VectorX2 = cos(deg2rad($Angle-90)) * $Force + ($X2-$X1)/2 +$X1; $VectorY2 = sin(deg2rad($Angle-90)) * $Force + ($RightY2-$LeftY2)/2 + $LeftY2; $Points = $Object->drawBezier($X1,$LeftY2,$X2,$RightY2,$VectorX1,$VectorY1,$VectorX2,$VectorY2,$Settings); $Points = array_reverse($Points); foreach($Points as $Key => $Pos) { $PolyGon[] = $Pos["X"]; $PolyGon[] = $Pos["Y"]; } $Object->drawPolygon($PolyGon,$Settings); if ( $TextPos == TEXT_POS_RIGHT ) { $Object->drawText($X2+$TextPadding,($RightY2-$RightY1)/2+$RightY1,$Label,array("Align"=>TEXT_ALIGN_MIDDLELEFT)); } else { $Object->drawText($X2,$RightY1-$TextPadding,$Label,array("Align"=>TEXT_ALIGN_BOTTOMRIGHT)); } $LeftY = $LeftY2; $RightY = $RightY2; } }
/** * Prepare the edit data for customer * @param type $mail * @param type $customer */ private function syncCustomerDataForRapidmail($mail, $customer) { // prepare data which can be saved $gender = ''; $dob = ''; $postcode = ''; $addressId = $customer->getData('default_shipping'); $address = Mage::getModel('customer/address')->load($addressId); $checkgender = $customer->getData('gender'); if (!empty($checkgender)) { $gender = Mage::helper('rapidmail')->convertGender($checkgender); } $checkdob = $customer->getData('dob'); if (!empty($checkdob)) { $dob = Mage::helper('rapidmail')->convertDob($checkdob); } if ($address) { $postcode = $address->getPostcode(); } // submit the new customer data to rapidmail Mage::helper('rapidmail')->editRecipient($mail, $customer->getFirstname(), $customer->getLastname(), $gender, $postcode, $dob); Mage::helper('rapidmail')->activateMail($mail); }
/** * Add values and rows to Svea CreateOrder object * * Configurable products: * Calculate prices using the parent price, to take price variations into concern * * Simple products: * Just use their prices as is * * Bundle products: * The main parent product has the price, but the associated products * need to be transferred on separate 0 amount lines so the invoice is * verbose enough * * Grouped products: * These are treated the same way as simple products * * @param type $order * @param type $additionalInfo * @return type Svea CreateOrder object */ public function getSveaPaymentObject($order, $additionalInfo = null) { //Get Request and billing addres $svea = $order->getData('svea_payment_request'); $billingAddress = $order->getBillingAddress(); $storeId = $order->getStoreId(); $store = Mage::app()->getStore($storeId); $taxCalculationModel = Mage::getSingleton('tax/calculation'); $taxConfig = Mage::getSingleton('tax/config'); // Build the rows for request foreach ($order->getAllItems() as $item) { if ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) { continue; } // Default to the item price $name = $item->getName(); $price = $item->getPrice(); $priceInclTax = $item->getPriceInclTax(); $taxPercent = $item->getTaxPercent(); if (!(int) $taxPercent) { $taxPercent = false; } $parentItem = $item->getParentItem(); if ($parentItem) { switch ($parentItem->getProductType()) { case Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE: $priceInclTax = $parentItem->getPriceInclTax(); $taxPercent = $parentItem->getTaxPercent(); break; case Mage_Catalog_Model_Product_Type::TYPE_BUNDLE: $taxPercent = $priceInclTax = $price = 0; $name = '- ' . $name; break; } } if ($taxPercent === false) { if ((double) $price === 0.0) { if ((double) $priceInclTax === 0.0) { $taxPercent = 0; } else { throw new Mage_Exception("Price is 0 but priceIncTax is not"); } } else { // If it's a bundle item we have to calculate the tax from // the including/excluding tax values $taxPercent = round(100 * ($priceInclTax / $price - 1)); } } $qty = get_class($item) == 'Mage_Sales_Model_Quote_Item' ? $item->getQty() : $item->getQtyOrdered(); $orderRow = WebPayItem::orderRow()->setArticleNumber($item->getSku())->setQuantity((int) $qty)->setName($name)->setUnit(Mage::helper('svea_webpay')->__('unit'))->setVatPercent((int) $taxPercent)->setAmountIncVat((double) $priceInclTax); $svea->addOrderRow($orderRow); } $request = $taxCalculationModel->getRateRequest($order->getShippingAddress(), $order->getBillingAddress(), null, $store); // Shipping if ($order->getShippingAmount() > 0) { $shippingFee = WebPayItem::shippingFee()->setUnit(Mage::helper('svea_webpay')->__('unit'))->setName($order->getShippingDescription()); // We require shipping tax to be set $shippingTaxClass = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, $storeId); $rate = $taxCalculationModel->getRate($request->setProductClassId($shippingTaxClass)); $shippingFee->setVatPercent((int) $rate); $shippingFee->setAmountIncVat($order->getShippingInclTax()); $svea->addFee($shippingFee); } // Discount $discount = abs($order->getDiscountAmount()); if ($discount > 0) { $discountRow = WebPayItem::fixedDiscount()->setName(Mage::helper('svea_webpay')->__('discount'))->setUnit(Mage::helper('svea_webpay')->__('unit'))->setAmountIncVat($discount); $svea->addDiscount($discountRow); } // Gift cards if (abs($order->getGiftCardsAmount()) > 0) { $giftCardRow = WebPayItem::fixedDiscount()->setUnit(Mage::helper('svea_webpay')->__('unit'))->setAmountIncVat(abs($order->getGiftCardsAmount())); $svea->addDiscount($giftCardRow); } // Invoice fee $paymentFeeInclTax = $order->getSveaPaymentFeeInclTax(); if ($paymentFeeInclTax > 0) { $paymentFeeTaxClass = $this->getConfigData('handling_fee_tax_class'); $rate = $taxCalculationModel->getRate($request->setProductClassId($paymentFeeTaxClass)); $invoiceFeeRow = WebPayItem::invoiceFee()->setUnit(Mage::helper('svea_webpay')->__('unit'))->setName(Mage::helper('svea_webpay')->__('invoice_fee'))->setVatPercent((int) $rate); $invoiceFeeRow->setAmountIncVat((double) $paymentFeeInclTax); $svea->addFee($invoiceFeeRow); } $svea->setCountryCode($billingAddress->getCountryId())->setClientOrderNumber($order->getIncrementId())->setOrderDate(date("Y-m-d"))->setCurrency($order->getOrderCurrencyCode()); return $svea; }
/** * Draw a radar chart * @param type $Object * @param type $Values * @param type $Format */ public function drawPolar($Object,$Values,$Format="") { $this->pChartObject = $Object; $FixedMax = isset($Format["FixedMax"]) ? $Format["FixedMax"] : VOID; $AxisR = isset($Format["AxisR"]) ? $Format["AxisR"] : 60; $AxisG = isset($Format["AxisG"]) ? $Format["AxisG"] : 60; $AxisB = isset($Format["AxisB"]) ? $Format["AxisB"] : 60; $AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 50; $AxisRotation = isset($Format["AxisRotation"]) ? $Format["AxisRotation"] : -90; $DrawTicks = isset($Format["DrawTicks"]) ? $Format["DrawTicks"] : true; $TicksLength = isset($Format["TicksLength"]) ? $Format["TicksLength"] : 2; $DrawAxisValues = isset($Format["DrawAxisValues"]) ? $Format["DrawAxisValues"] : true; $AxisBoxRounded = isset($Format["AxisBoxRounded"]) ? $Format["AxisBoxRounded"] : true; $AxisFontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName; $AxisFontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize; $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : false; $WriteValuesInBubble = isset($Format["WriteValuesInBubble"]) ? $Format["WriteValuesInBubble"] : true; $ValueFontName = isset($Format["ValueFontName"]) ? $Format["ValueFontName"] : $this->pChartObject->FontName; $ValueFontSize = isset($Format["ValueFontSize"]) ? $Format["ValueFontSize"] : $this->pChartObject->FontSize; $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 4; $OuterBubbleRadius = isset($Format["OuterBubbleRadius"]) ? $Format["OuterBubbleRadius"] : 2; $OuterBubbleR = isset($Format["OuterBubbleR"]) ? $Format["OuterBubbleR"] : VOID; $OuterBubbleG = isset($Format["OuterBubbleG"]) ? $Format["OuterBubbleG"] : VOID; $OuterBubbleB = isset($Format["OuterBubbleB"]) ? $Format["OuterBubbleB"] : VOID; $OuterBubbleAlpha = isset($Format["OuterBubbleAlpha"]) ? $Format["OuterBubbleAlpha"] : 100; $InnerBubbleR = isset($Format["InnerBubbleR"]) ? $Format["InnerBubbleR"] : 255; $InnerBubbleG = isset($Format["InnerBubbleG"]) ? $Format["InnerBubbleG"] : 255; $InnerBubbleB = isset($Format["InnerBubbleB"]) ? $Format["InnerBubbleB"] : 255; $InnerBubbleAlpha = isset($Format["InnerBubbleAlpha"]) ? $Format["InnerBubbleAlpha"] : 100; $DrawBackground = isset($Format["DrawBackground"]) ? $Format["DrawBackground"] : true; $BackgroundR = isset($Format["BackgroundR"]) ? $Format["BackgroundR"] : 255; $BackgroundG = isset($Format["BackgroundG"]) ? $Format["BackgroundG"] : 255; $BackgroundB = isset($Format["BackgroundB"]) ? $Format["BackgroundB"] : 255; $BackgroundAlpha = isset($Format["BackgroundAlpha"]) ? $Format["BackgroundAlpha"] : 50; $BackgroundGradient= isset($Format["BackgroundGradient"]) ? $Format["BackgroundGradient"] : null; $AxisSteps = isset($Format["AxisSteps"]) ? $Format["AxisSteps"] : 20; $SegmentHeight = isset($Format["SegmentHeight"]) ? $Format["SegmentHeight"] : SEGMENT_HEIGHT_AUTO; $Segments = isset($Format["Segments"]) ? $Format["Segments"] : 4; $WriteLabels = isset($Format["WriteLabels"]) ? $Format["WriteLabels"] : true; $LabelsBackground = isset($Format["LabelsBackground"]) ? $Format["LabelsBackground"] : true; $LabelsBGR = isset($Format["LabelsBGR"]) ? $Format["LabelsBGR"] : 255; $LabelsBGG = isset($Format["LabelsBGR"]) ? $Format["LabelsBGG"] : 255; $LabelsBGB = isset($Format["LabelsBGR"]) ? $Format["LabelsBGB"] : 255; $LabelsBGAlpha = isset($Format["LabelsBGAlpha"]) ? $Format["LabelsBGAlpha"] : 50; $LabelPos = isset($Format["LabelPos"]) ? $Format["LabelPos"] : RADAR_LABELS_ROTATED; $LabelPadding = isset($Format["LabelPadding"]) ? $Format["LabelPadding"] : 4; $DrawPoints = isset($Format["DrawPoints"]) ? $Format["DrawPoints"] : true; $PointRadius = isset($Format["PointRadius"]) ? $Format["PointRadius"] : 4; $PointSurrounding = isset($Format["PointRadius"]) ? $Format["PointRadius"] : -30; $DrawLines = isset($Format["DrawLines"]) ? $Format["DrawLines"] : true; $LineLoopStart = isset($Format["LineLoopStart"]) ? $Format["LineLoopStart"] : false; $DrawPoly = isset($Format["DrawPoly"]) ? $Format["DrawPoly"] : false; $PolyAlpha = isset($Format["PolyAlpha"]) ? $Format["PolyAlpha"] : null; $FontSize = $Object->FontSize; $X1 = $Object->GraphAreaX1; $Y1 = $Object->GraphAreaY1; $X2 = $Object->GraphAreaX2; $Y2 = $Object->GraphAreaY2; $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : false; if ( $AxisBoxRounded ) { $DrawAxisValues = true; } /* Cancel default tick length if ticks not enabled */ if ( $DrawTicks == false ) { $TicksLength = 0; } /* Data Processing */ $Data = $Values->getData(); $Palette = $Values->getPalette(); /* Catch the number of required axis */ $LabelSerie = $Data["Abscissa"]; if ( $LabelSerie != "" ) { $Points = count($Data["Series"][$LabelSerie]["Data"]); } else { $Points = 0; foreach($Data["Series"] as $SerieName => $DataArray) { if ( count($DataArray["Data"]) > $Points ) { $Points = count($DataArray["Data"]); } } } /* Draw the axis */ $CenterX = ($X2-$X1)/2 + $X1; $CenterY = ($Y2-$Y1)/2 + $Y1; $EdgeHeight = min(($X2-$X1)/2,($Y2-$Y1)/2); if ( $WriteLabels ) { $EdgeHeight = $EdgeHeight - $FontSize - $LabelPadding - $TicksLength; } /* Determine the scale if set to automatic */ if ( $SegmentHeight == SEGMENT_HEIGHT_AUTO) { if ( $FixedMax != VOID ) { $Max = $FixedMax; } else { $Max = 0; foreach($Data["Series"] as $SerieName => $DataArray) { if ( $SerieName != $LabelSerie ) { if ( max($DataArray["Data"]) > $Max ) { $Max = max($DataArray["Data"]); } } } } $MaxSegments = $EdgeHeight/20; $Scale = $Object->computeScale(0,$Max,$MaxSegments,array(1,2,5)); $Segments = $Scale["Rows"]; $SegmentHeight = $Scale["RowHeight"]; } /* Background processing */ if ( $DrawBackground ) { $RestoreShadow = $Object->Shadow; $Object->Shadow = false; if ($BackgroundGradient == null) { $Color = array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha); $Object->drawFilledCircle($CenterX,$CenterY,$EdgeHeight,$Color); } else { $GradientROffset = ($BackgroundGradient["EndR"] - $BackgroundGradient["StartR"]) / $Segments; $GradientGOffset = ($BackgroundGradient["EndG"] - $BackgroundGradient["StartG"]) / $Segments; $GradientBOffset = ($BackgroundGradient["EndB"] - $BackgroundGradient["StartB"]) / $Segments; $GradientAlphaOffset = ($BackgroundGradient["EndAlpha"] - $BackgroundGradient["StartAlpha"]) / $Segments; for ($j=$Segments;$j>=1;$j--) { $Color = array( "R"=>$BackgroundGradient["StartR"]+$GradientROffset*$j, "G"=>$BackgroundGradient["StartG"]+$GradientGOffset*$j, "B"=>$BackgroundGradient["StartB"]+$GradientBOffset*$j, "Alpha"=>$BackgroundGradient["StartAlpha"]+$GradientAlphaOffset*$j ); $Object->drawFilledCircle($CenterX,$CenterY,($EdgeHeight/$Segments)*$j,$Color); } } $Object->Shadow = $RestoreShadow; } /* Axis to axis lines */ $Color = array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha); for($j=1;$j<=$Segments;$j++) { $Radius = ($EdgeHeight/$Segments)*$j; $Object->drawCircle($CenterX,$CenterY,$Radius,$Radius,$Color); } if ( $DrawAxisValues ) { if ( $LabelsBackground ) { $Options = array( "DrawBox"=>true, "Align"=>TEXT_ALIGN_MIDDLEMIDDLE, "BoxR"=>$LabelsBGR, "BoxG"=>$LabelsBGG, "BoxB"=>$LabelsBGB, "BoxAlpha"=>$LabelsBGAlpha ); } else { $Options = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE); } if ( $AxisBoxRounded ) { $Options["BoxRounded"] = true; } $Options["FontName"] = $AxisFontName; $Options["FontSize"] = $AxisFontSize; $Angle = 360 / ($Points*2); for($j=1;$j<=$Segments;$j++) { $EdgeX1 = cos(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX; $EdgeY1 = sin(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY; $Label = $j*$SegmentHeight; $Object->drawText($EdgeX1,$EdgeY1,$Label,$Options); } } /* Axis lines */ $ID = 0; for($i=0;$i<=359;$i=$i+$AxisSteps) { $EdgeX = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$TicksLength) + $CenterX; $EdgeY = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$TicksLength) + $CenterY; $Object->drawLine($CenterX,$CenterY,$EdgeX,$EdgeY,$Color); if ( $WriteLabels ) { $LabelX = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$LabelPadding+$TicksLength) + $CenterX; $LabelY = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$LabelPadding+$TicksLength) + $CenterY; $Label = $i."°"; if ( $LabelPos == RADAR_LABELS_ROTATED ) { $Object->drawText($LabelX,$LabelY,$Label,array("Angle"=>(360-$i),"Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); } else { if ( (floor($LabelX) == floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); } if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMLEFT)); } if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) == floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_MIDDLELEFT)); } if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPLEFT)); } if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMRIGHT)); } if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) == floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); } if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPRIGHT)); } if ( (floor($LabelX) == floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPMIDDLE)); } } } $ID++; } /* Compute the plots position */ $ID = 0; $Plot = ""; foreach($Data["Series"] as $SerieName => $DataSet) { if ( $SerieName != $LabelSerie ) { $Color = array( "R"=>$Palette[$ID]["R"], "G"=>$Palette[$ID]["G"], "B"=>$Palette[$ID]["B"], "Alpha"=>$Palette[$ID]["Alpha"], "Surrounding"=>$PointSurrounding ); foreach($DataSet["Data"] as $Key => $Value) { $Angle = $Data["Series"][$LabelSerie]["Data"][$Key]; $Length = ($EdgeHeight/($Segments*$SegmentHeight))*$Value; $X = cos(deg2rad($Angle+$AxisRotation)) * $Length + $CenterX; $Y = sin(deg2rad($Angle+$AxisRotation)) * $Length + $CenterY; if ( $RecordImageMap ) { $this->pChartObject->addToImageMap( "CIRCLE",floor($X).",".floor($Y).",".floor($PointRadius), $this->pChartObject->toHTMLColor( $Palette[$ID]["R"], $Palette[$ID]["G"], $Palette[$ID]["B"] ), $DataSet["Description"], $Data["Series"][$LabelSerie]["Data"][$Key]."° = ".$Value ); } $Plot[$ID][] = array($X,$Y,$Value); } $ID++; } } /* Draw all that stuff! */ foreach($Plot as $ID => $Points) { $Color = array( "R"=>$Palette[$ID]["R"], "G"=>$Palette[$ID]["G"], "B"=>$Palette[$ID]["B"], "Alpha"=>$Palette[$ID]["Alpha"], "Surrounding"=>$PointSurrounding ); /* Draw the polygons */ if ( $DrawPoly ) { if ($PolyAlpha != null) { $Color = array( "R"=>$Palette[$ID]["R"], "G"=>$Palette[$ID]["G"], "B"=>$Palette[$ID]["B"], "Alpha"=>$PolyAlpha, "Surrounding"=>$PointSurrounding ); } $PointsArray = ""; for ($i=0; $i<count($Points);$i++) { $PointsArray[] = $Points[$i][0]; $PointsArray[] = $Points[$i][1]; } $Object->drawPolygon($PointsArray,$Color); } $Color = array( "R"=>$Palette[$ID]["R"], "G"=>$Palette[$ID]["G"], "B"=>$Palette[$ID]["B"], "Alpha"=>$Palette[$ID]["Alpha"], "Surrounding"=>$PointSurrounding ); /* Bubble and labels settings */ $TextSettings = array( "Align"=>TEXT_ALIGN_MIDDLEMIDDLE, "FontName"=>$ValueFontName, "FontSize"=>$ValueFontSize, "R"=>$Palette[$ID]["R"], "G"=>$Palette[$ID]["G"], "B"=>$Palette[$ID]["B"] ); $InnerColor = array( "R"=>$InnerBubbleR, "G"=>$InnerBubbleG, "B"=>$InnerBubbleB, "Alpha"=>$InnerBubbleAlpha ); if ( $OuterBubbleR != VOID ) { $OuterColor = array( "R"=>$OuterBubbleR, "G"=>$OuterBubbleG, "B"=>$OuterBubbleB, "Alpha"=>$OuterBubbleAlpha ); } else { $OuterColor = array( "R"=>$Palette[$ID]["R"]+20, "G"=>$Palette[$ID]["G"]+20, "B"=>$Palette[$ID]["B"]+20, "Alpha"=>$Palette[$ID]["Alpha"] ); } /* Loop to the starting points if asked */ if ( $LineLoopStart && $DrawLines ) { $Object->drawLine( $Points[count($Points)-1][0], $Points[count($Points)-1][1], $Points[0][0], $Points[0][1], $Color ); } /* Draw the lines & points */ for ($i=0; $i<count($Points);$i++) { if ( $DrawLines && $i < count($Points)-1) { $Object->drawLine( $Points[$i][0], $Points[$i][1], $Points[$i+1][0], $Points[$i+1][1], $Color ); } if ( $DrawPoints ) { $Object->drawFilledCircle( $Points[$i][0], $Points[$i][1], $PointRadius, $Color ); } if ( $WriteValuesInBubble && $WriteValues ) { $TxtPos = $this->pChartObject->getTextBox( $Points[$i][0], $Points[$i][1], $ValueFontName, $ValueFontSize, 0, $Points[$i][2] ); $Radius = floor(($TxtPos[1]["X"] - $TxtPos[0]["X"] + $ValuePadding*2)/2); $this->pChartObject->drawFilledCircle($Points[$i][0],$Points[$i][1],$Radius+$OuterBubbleRadius,$OuterColor); $this->pChartObject->drawFilledCircle($Points[$i][0],$Points[$i][1],$Radius,$InnerColor); } if ( $WriteValues ) { $this->pChartObject->drawText($Points[$i][0]-1,$Points[$i][1]-1,$Points[$i][2],$TextSettings); } } } }