/** * Filters the summaries by some period * * @param string $periodType * @param string|int|null $customStart * @param string|int|null $customEnd * @return Mage_Reports_Model_Resource_Entity_Summary_Collection_Abstract */ public function setSelectPeriod($periodType, $customStart = null, $customEnd = null) { switch ($periodType) { case "24h": $customStart = Varien_Date::toTimestamp(true) - 86400; $customEnd = Varien_Date::toTimestamp(true); break; case "7d": $customStart = Varien_Date::toTimestamp(true) - 604800; $customEnd = Varien_Date::toTimestamp(true); break; case "30d": $customStart = Varien_Date::toTimestamp(true) - 2592000; $customEnd = Varien_Date::toTimestamp(true); break; case "1y": $customStart = Varien_Date::toTimestamp(true) - 31536000; $customEnd = Varien_Date::toTimestamp(true); break; default: if (is_string($customStart)) { $customStart = strtotime($customStart); } if (is_string($customEnd)) { $customEnd = strtotime($customEnd); } break; } return $this; }
/** * Perform actions before object save * * @param Mage_Core_Model_Abstract $object * @return Mage_Core_Model_Resource_Db_Abstract * @throws Mage_Core_Exception */ public function _beforeSave(Mage_Core_Model_Abstract $object) { if ($date = $object->getDateFrom()) { $object->setDateFrom($this->formatDate($date)); } else { $object->setDateFrom(null); } if ($date = $object->getDateTo()) { $object->setDateTo($this->formatDate($date)); } else { $object->setDateTo(null); } if (!is_null($object->getDateFrom()) && !is_null($object->getDateTo()) && Varien_Date::toTimestamp($object->getDateFrom()) > Varien_Date::toTimestamp($object->getDateTo())) { Mage::throwException(Mage::helper('core')->__('Start date cannot be greater than end date.')); } $check = $this->_checkIntersection($object->getStoreId(), $object->getDateFrom(), $object->getDateTo(), $object->getId()); if ($check) { Mage::throwException(Mage::helper('core')->__('Your design change for the specified store intersects with another one, please specify another date range.')); } if ($object->getDateFrom() === null) { $object->setDateFrom(new Zend_Db_Expr('null')); } if ($object->getDateTo() === null) { $object->setDateTo(new Zend_Db_Expr('null')); } parent::_beforeSave($object); }
public function testToTimestamp() { $date = new Zend_Date(); $this->assertEquals($date->getTimestamp(), Varien_Date::toTimestamp($date)); $this->assertEquals(time(), Varien_Date::toTimestamp(true)); $date = '2012-07-19 16:52'; $this->assertEquals(strtotime($date), Varien_Date::toTimestamp($date)); }
/** * Return last login at in Unix time format * * @return int */ public function getLoginAtTimestamp() { $loginAt = $this->getLoginAt(); if ($loginAt) { return Varien_Date::toTimestamp($loginAt); } return null; }
/** * Update tax percents for WEEE based on products condition * * @param mixed $productCondition * @return Mage_Weee_Model_Resource_Tax */ protected function _updateDiscountPercents($productCondition = null) { $now = Varien_Date::toTimestamp(Varien_Date::now()); $adapter = $this->_getWriteAdapter(); $select = $this->_getReadAdapter()->select(); $select->from(array('data' => $this->getTable('catalogrule/rule_product'))); $deleteCondition = ''; if ($productCondition) { if ($productCondition instanceof Mage_Catalog_Model_Product) { $select->where('product_id = ?', (int) $productCondition->getId()); $deleteCondition = $adapter->quoteInto('entity_id=?', (int) $productCondition->getId()); } elseif ($productCondition instanceof Mage_Catalog_Model_Product_Condition_Interface) { $productCondition = $productCondition->getIdsSelect($adapter)->__toString(); $select->where("product_id IN ({$productCondition})"); $deleteCondition = "entity_id IN ({$productCondition})"; } else { $select->where('product_id = ?', (int) $productCondition); $deleteCondition = $adapter->quoteInto('entity_id = ?', (int) $productCondition); } } else { $select->where('(from_time <= ? OR from_time = 0)', $now)->where('(to_time >= ? OR to_time = 0)', $now); } $adapter->delete($this->getTable('weee/discount'), $deleteCondition); $select->order(array('data.website_id', 'data.customer_group_id', 'data.product_id', 'data.sort_order')); $data = $this->_getReadAdapter()->query($select); $productData = array(); $stops = array(); $prevKey = false; while ($row = $data->fetch()) { $key = "{$row['product_id']}-{$row['website_id']}-{$row['customer_group_id']}"; if (isset($stops[$key]) && $stops[$key]) { continue; } if ($prevKey && $prevKey != $key) { foreach ($productData as $product) { $adapter->insert($this->getTable('weee/discount'), $product); } $productData = array(); } if ($row['action_operator'] == 'by_percent') { if (isset($productData[$key])) { $productData[$key]['value'] -= $productData[$key]['value'] / 100 * $row['action_amount']; } else { $productData[$key] = array('entity_id' => $row['product_id'], 'customer_group_id' => $row['customer_group_id'], 'website_id' => $row['website_id'], 'value' => 100 - $row['action_amount']); } } if ($row['action_stop']) { $stops[$key] = true; } $prevKey = $key; } foreach ($productData as $product) { $adapter->insert($this->getTable('weee/discount'), $product); } return $this; }
/** * Saves flag * * @param string $code * @param mixed $value * @return Mage_Reports_Model_Resource_Report_Abstract */ protected function _setFlagData($code, $value = null) { $this->_getFlag()->setReportFlagCode($code)->unsetData()->loadSelf(); if ($value !== null) { $this->_getFlag()->setFlagData($value); } $time = Varien_Date::toTimestamp(true); // touch last_update $this->_getFlag()->setLastUpdate($this->formatDate($time)); $this->_getFlag()->save(); return $this; }
/** * Perform actions before object save * * @param Mage_Core_Model_Abstract $object * @return Mage_Core_Model_Resource_Db_Abstract * @throws Mage_Core_Exception */ public function _beforeSave(Mage_Core_Model_Abstract $object) { $dateFrom = $object->getDateFrom(); $dateTo = $object->getDateTo(); if (!empty($dateFrom) && !empty($dateTo)) { $validator = new Zend_Validate_Date(); if (!$validator->isValid($dateFrom) || !$validator->isValid($dateTo)) { Mage::throwException(Mage::helper('core')->__('Invalid date')); } if (Varien_Date::toTimestamp($dateFrom) > Varien_Date::toTimestamp($dateTo)) { Mage::throwException(Mage::helper('core')->__('Start date cannot be greater than end date.')); } } $check = $this->_checkIntersection($object->getStoreId(), $dateFrom, $dateTo, $object->getId()); if ($check) { Mage::throwException(Mage::helper('core')->__('Your design change for the specified store intersects with another one, please specify another date range.')); } parent::_beforeSave($object); }
/** * Get formated date in store timezone * * @param string $date * @return string */ public function getFormatedDate($date) { $storeDate = Mage::app()->getLocale()->storeDate(Mage::app()->getStore(), Varien_Date::toTimestamp($date), true); return Mage::helper('core')->formatDate($storeDate, Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); }
/** * Garbage collection * * @param int $sessMaxLifeTime ignored * @return boolean */ public function gc($sessMaxLifeTime) { if ($this->_automaticCleaningFactor > 0) { if ($this->_automaticCleaningFactor == 1 || rand(1, $this->_automaticCleaningFactor) == 1) { $where = array('session_expires < ?' => Varien_Date::toTimestamp(true)); $this->_write->delete($this->_sessionTable, $where); } } return true; }
/** * Insert order to pdf page * * @param Zend_Pdf_Page $page * @param Mage_Sales_Model_Order $obj * @param bool $putOrderId */ protected function insertOrder(&$page, $obj, $putOrderId = true) { if ($obj instanceof Mage_Sales_Model_Order) { $shipment = null; $order = $obj; } elseif ($obj instanceof Mage_Sales_Model_Order_Shipment) { $shipment = $obj; $order = $shipment->getOrder(); } $this->y = $this->y ? $this->y : 815; $top = $this->y; $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.45)); $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.45)); #$page->drawRectangle(25, $top, 570, $top - 55); $page->drawRectangle(25, $top, 570, $top - 75); $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $this->setDocHeaderCoordinates(array(25, $top, 570, $top - 55)); $this->_setFontRegular($page, 10); if ($putOrderId) { $page->drawText(Mage::helper('sales')->__('Order # ') . $order->getRealOrderId(), 35, $top -= 30, 'UTF-8'); } $page->drawText(Mage::helper('sales')->__('Order Date: ') . Mage::helper('core')->formatDate($order->getCreatedAtStoreDate(), 'medium', false), 35, $top -= 15, 'UTF-8'); if ($order->hasInvoices()) { foreach ($order->getInvoiceCollection() as $invoice) { $invoiceIncrementID = $invoice->getIncrementId(); $invoiceObj = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceIncrementID); $invoiceDate = $invoiceObj->getCreatedAt(); $invoiceDueDate = Mage::app()->getLocale()->storeDate($order->getStore(), Varien_Date::toTimestamp($invoiceDate) + 7 * 24 * 60 * 60, true, $format); } $page->drawText(Mage::helper('sales')->__('Invoice Due Date: ') . Mage::helper('core')->formatDate($invoiceDueDate, 'medium', false), 35, $top -= 15, 'UTF-8'); } if ($order->getData('dynamics_ord') !== null) { $page->drawText(Mage::helper('sales')->__('Invoice Custom Comment: ') . $order->getDynamicsOrd(), 35, $top -= 15, 'UTF-8'); } $top -= 10; $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92)); $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5)); $page->setLineWidth(0.5); $page->drawRectangle(25, $top, 275, $top - 25); $page->drawRectangle(275, $top, 570, $top - 25); /* Calculate blocks info */ /* Billing Address */ $billingAddress = $this->_formatAddress($order->getBillingAddress()->format('pdf')); /* Payment */ $paymentInfo = Mage::helper('payment')->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toPdf(); $paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES); $payment = explode('{{pdf_row_separator}}', $paymentInfo); foreach ($payment as $key => $value) { if (strip_tags(trim($value)) == '') { unset($payment[$key]); } } reset($payment); /* Shipping Address and Method */ if (!$order->getIsVirtual()) { /* Shipping Address */ $shippingAddress = $this->_formatAddress($order->getShippingAddress()->format('pdf')); $shippingMethod = $order->getShippingDescription(); } $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $this->_setFontBold($page, 12); $page->drawText(Mage::helper('sales')->__('Sold to:'), 35, $top - 15, 'UTF-8'); if (!$order->getIsVirtual()) { $page->drawText(Mage::helper('sales')->__('Ship to:'), 285, $top - 15, 'UTF-8'); } else { $page->drawText(Mage::helper('sales')->__('Payment Method:'), 285, $top - 15, 'UTF-8'); } $addressesHeight = $this->_calcAddressHeight($billingAddress); if (isset($shippingAddress)) { $addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress)); } $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $page->drawRectangle(25, $top - 25, 570, $top - 33 - $addressesHeight); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $this->_setFontRegular($page, 10); $this->y = $top - 40; $addressesStartY = $this->y; foreach ($billingAddress as $value) { if ($value !== '') { $text = array(); foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) { $text[] = $_value; } foreach ($text as $part) { $page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8'); $this->y -= 15; } } } $addressesEndY = $this->y; if (!$order->getIsVirtual()) { $this->y = $addressesStartY; foreach ($shippingAddress as $value) { if ($value !== '') { $text = array(); foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) { $text[] = $_value; } foreach ($text as $part) { $page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8'); $this->y -= 15; } } } $addressesEndY = min($addressesEndY, $this->y); $this->y = $addressesEndY; $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92)); $page->setLineWidth(0.5); $page->drawRectangle(25, $this->y, 275, $this->y - 25); $page->drawRectangle(275, $this->y, 570, $this->y - 25); $this->y -= 15; $this->_setFontBold($page, 12); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $page->drawText(Mage::helper('sales')->__('Payment Method'), 35, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Shipping Method:'), 285, $this->y, 'UTF-8'); $this->y -= 10; $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $this->_setFontRegular($page, 10); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $paymentLeft = 35; $yPayments = $this->y - 15; } else { $yPayments = $addressesStartY; $paymentLeft = 285; } foreach ($payment as $value) { if (trim($value) != '') { //Printing "Payment Method" lines $value = preg_replace('/<br[^>]*>/i', "\n", $value); foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) { $page->drawText(strip_tags(trim($_value)), $paymentLeft, $yPayments, 'UTF-8'); $yPayments -= 15; } } } if ($order->getIsVirtual()) { // replacement of Shipments-Payments rectangle block $yPayments = min($addressesEndY, $yPayments); $page->drawLine(25, $top - 25, 25, $yPayments); $page->drawLine(570, $top - 25, 570, $yPayments); $page->drawLine(25, $yPayments, 570, $yPayments); $this->y = $yPayments - 15; } else { $topMargin = 15; $methodStartY = $this->y; $this->y -= 15; foreach (Mage::helper('core/string')->str_split($shippingMethod, 45, true, true) as $_value) { $page->drawText(strip_tags(trim($_value)), 285, $this->y, 'UTF-8'); $this->y -= 15; } $yShipments = $this->y; $totalShippingChargesText = "(" . Mage::helper('sales')->__('Total Shipping Charges') . " " . $order->formatPriceTxt($order->getShippingAmount()) . ")"; $page->drawText($totalShippingChargesText, 285, $yShipments - $topMargin, 'UTF-8'); $yShipments -= $topMargin + 10; $tracks = array(); if ($shipment) { $tracks = $shipment->getAllTracks(); } if (count($tracks)) { $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92)); $page->setLineWidth(0.5); $page->drawRectangle(285, $yShipments, 510, $yShipments - 10); $page->drawLine(400, $yShipments, 400, $yShipments - 10); //$page->drawLine(510, $yShipments, 510, $yShipments - 10); $this->_setFontRegular($page, 9); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); //$page->drawText(Mage::helper('sales')->__('Carrier'), 290, $yShipments - 7 , 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Title'), 290, $yShipments - 7, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Number'), 410, $yShipments - 7, 'UTF-8'); $yShipments -= 20; $this->_setFontRegular($page, 8); foreach ($tracks as $track) { $CarrierCode = $track->getCarrierCode(); if ($CarrierCode != 'custom') { $carrier = Mage::getSingleton('shipping/config')->getCarrierInstance($CarrierCode); $carrierTitle = $carrier->getConfigData('title'); } else { $carrierTitle = Mage::helper('sales')->__('Custom Value'); } //$truncatedCarrierTitle = substr($carrierTitle, 0, 35) . (strlen($carrierTitle) > 35 ? '...' : ''); $maxTitleLen = 45; $endOfTitle = strlen($track->getTitle()) > $maxTitleLen ? '...' : ''; $truncatedTitle = substr($track->getTitle(), 0, $maxTitleLen) . $endOfTitle; //$page->drawText($truncatedCarrierTitle, 285, $yShipments , 'UTF-8'); $page->drawText($truncatedTitle, 292, $yShipments, 'UTF-8'); $page->drawText($track->getNumber(), 410, $yShipments, 'UTF-8'); $yShipments -= $topMargin - 5; } } else { $yShipments -= $topMargin - 5; } $currentY = min($yPayments, $yShipments); // replacement of Shipments-Payments rectangle block $page->drawLine(25, $methodStartY, 25, $currentY); //left $page->drawLine(25, $currentY, 570, $currentY); //bottom $page->drawLine(570, $currentY, 570, $methodStartY); //right $this->y = $currentY; $this->y -= 15; } }
/** * Convert internal date to UNIX timestamp * * @param string $str * @return int */ public function mktime($str) { return Varien_Date::toTimestamp($str); }
/** * Add information about product ids to visitor/customer * * * @param Mage_Reports_Model_Product_Index_Abstract $object * @param array $productIds * @return Mage_Reports_Model_Resource_Product_Index_Abstract */ public function registerIds(Varien_Object $object, $productIds) { $row = array('visitor_id' => $object->getVisitorId(), 'customer_id' => $object->getCustomerId(), 'store_id' => $object->getStoreId()); $addedAt = Varien_Date::toTimestamp(true); $data = array(); foreach ($productIds as $productId) { $productId = (int) $productId; if ($productId) { $row['product_id'] = $productId; $row['added_at'] = Varien_Date::formatDate($addedAt); $data[] = $row; } $addedAt -= $addedAt > 0 ? 1 : 0; } $matchFields = array('product_id', 'store_id'); foreach ($data as $row) { Mage::getResourceHelper('reports')->mergeVisitorProductIndex($this->getMainTable(), $row, $matchFields); } return $this; }
/** * Get object created at date affected with object store timezone * * @return Zend_Date */ public function getCreatedAtStoreDate() { return Mage::app()->getLocale()->storeDate($this->getStore(), Varien_Date::toTimestamp($this->getCreatedAt()), true); }
/** * Check if email is expired and should not * get send out anymore * * @param integer $now * @return boolean */ public function isExpired($now = null) { if (!$now) { $now = time(); } if ($this->getExpireAt()) { $expireAt = Varien_Date::toTimestamp($this->getExpireAt()); return $expireAt < $now; } return false; }
/** * Get the timestamp of the latest update * * @return int|null */ public function getUpdatedAtTimestamp() { $date = $this->getUpdatedAt(); if ($date) { return Varien_Date::toTimestamp($date); } return null; }
public function callGetTaxForQuote(Mage_Sales_Model_Quote $quote) { /** @var Aoe_AvaTax_Helper_Soap $helper */ $helper = Mage::helper('Aoe_AvaTax/Soap'); $address = $quote->getShippingAddress(); if ($address->validate() !== true) { $resultArray = array('ResultCode' => 'Skip', 'Messages' => array(), 'TaxLines' => array()); return $resultArray; } $store = $quote->getStore(); $hideDiscountAmount = Mage::getStoreConfigFlag(Mage_Tax_Model_Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT, $store); $timestamp = $quote->getCreatedAt() ? Varien_Date::toTimestamp($quote->getCreatedAt()) : now(); $date = new Zend_Date($timestamp); $request = new AvaTax\GetTaxRequest(); $request->setCompanyCode($this->limit($helper->getConfig('company_code', $store), 25)); $request->setDocType(AvaTax\DocumentType::$SalesOrder); $request->setCommit(false); $request->setDetailLevel(AvaTax\DetailLevel::$Tax); $request->setDocDate($date->toString('yyyy-MM-dd')); $request->setCustomerCode($helper->getCustomerDocCode($quote->getCustomer()) ?: $helper->getQuoteDocCode($quote)); $request->setCurrencyCode($this->limit($quote->getBaseCurrencyCode(), 3)); $request->setDiscount($hideDiscountAmount ? 0.0 : $store->roundPrice($address->getBaseDiscountAmount())); if ($quote->getCustomerTaxvat()) { $request->setBusinessIdentificationNo($this->limit($quote->getCustomerTaxvat(), 25)); } $request->setOriginAddress($this->getOriginAddress($store)); $request->setDestinationAddress($this->getAddress($address)); $taxLines = array(); $itemPriceIncludesTax = Mage::getStoreConfigFlag(Mage_Tax_Model_Config::CONFIG_XML_PATH_PRICE_INCLUDES_TAX, $store); foreach ($this->getHelper()->getActionableQuoteAddressItems($address) as $k => $item) { /** @var Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Quote_Address_Item $item */ $itemAmount = $store->roundPrice($itemPriceIncludesTax ? $item->getBaseRowTotalInclTax() : $item->getBaseRowTotal()); //$itemAmount = $store->roundPrice($item->getBaseRowTotal()); $itemAmount -= $store->roundPrice($item->getBaseDiscountAmount()); $taxLine = new AvaTax\Line(); $taxLine->setNo($this->limit($k, 50)); $taxLine->setItemCode($this->limit($item->getSku(), 50)); $taxLine->setQty(round($item->getQty(), 4)); $taxLine->setAmount($itemAmount); $taxLine->setDescription($this->limit($item->getName(), 255)); $taxLine->setTaxCode($this->limit($helper->getProductTaxCode($item->getProduct()), 25)); $taxLine->setDiscounted($item->getBaseDiscountAmount() > 0.0); $taxLine->setTaxIncluded($itemPriceIncludesTax); $taxLine->setRef1($this->limit($helper->getQuoteItemRef1($item, $store), 250)); $taxLine->setRef2($this->limit($helper->getQuoteItemRef2($item, $store), 250)); $taxLines[] = $taxLine; } $shippingPriceIncludesTax = Mage::getStoreConfigFlag(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX, $store); $shippingAmount = $store->roundPrice($shippingPriceIncludesTax ? $address->getBaseShippingInclTax() : $address->getBaseShippingAmount()); //$shippingAmount = $store->roundPrice($address->getBaseShippingAmount()); $shippingAmount -= $store->roundPrice($address->getBaseShippingDiscountAmount()); $taxLine = new AvaTax\Line(); $taxLine->setNo('SHIPPING'); $taxLine->setItemCode('SHIPPING'); $taxLine->setQty(1); $taxLine->setAmount($shippingAmount); $taxLine->setDescription($this->limit("Shipping: " . $address->getShippingMethod(), 255)); $taxLine->setTaxCode($this->limit($helper->getShippingTaxCode($store), 25)); $taxLine->setDiscounted($address->getBaseShippingDiscountAmount() > 0.0); $taxLine->setTaxIncluded($shippingPriceIncludesTax); $taxLine->setRef1($this->limit($address->getShippingMethod(), 25)); $taxLines[] = $taxLine; $request->setLines($taxLines); Mage::dispatchEvent('aoe_avatax_soapapi_get_tax_for_quote_before', array('request' => $request, 'quote' => $quote)); // TODO: Handle giftwrapping return $this->callGetTax($store, $request); }
/** * Transform date to store format * * @param string $date * @return Zend_Date */ public function transformDate($date) { return Mage::app()->getLocale()->storeDate($this->getCustomer()->getStoreId(), Varien_Date::toTimestamp($date)); }
/** * Check if current reset password link token is expired * * @return boolean */ public function isResetPasswordLinkTokenExpired() { $resetPasswordLinkToken = $this->getRpToken(); $resetPasswordLinkTokenCreatedAt = $this->getRpTokenCreatedAt(); if (empty($resetPasswordLinkToken) || empty($resetPasswordLinkTokenCreatedAt)) { return true; } $tokenExpirationPeriod = Mage::helper('admin')->getResetPasswordLinkExpirationPeriod(); $currentDate = Varien_Date::now(); $currentTimestamp = Varien_Date::toTimestamp($currentDate); $tokenTimestamp = Varien_Date::toTimestamp($resetPasswordLinkTokenCreatedAt); if ($tokenTimestamp > $currentTimestamp) { return true; } $dayDifference = floor(($currentTimestamp - $tokenTimestamp) / (24 * 60 * 60)); if ($dayDifference >= $tokenExpirationPeriod) { return true; } return false; }
protected function createTaxRequestFromQuoteAddress(Mage_Sales_Model_Quote_Address $address) { $quote = $address->getQuote(); $store = $quote->getStore(); $hideDiscountAmount = Mage::getStoreConfigFlag(Mage_Tax_Model_Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT, $store); $timestamp = $quote->getCreatedAt() ? Varien_Date::toTimestamp($quote->getCreatedAt()) : now(); $date = new Zend_Date($timestamp); $request = array('Client' => 'Aoe_AvaTax', 'CompanyCode' => $this->limit($this->getHelper()->getConfig('company_code', $store), 25), 'DocType' => 'SalesOrder', 'Commit' => false, 'DetailLevel' => 'Tax', 'DocDate' => $date->toString('yyyy-MM-dd'), 'CustomerCode' => $this->getHelper()->getCustomerDocCode($quote->getCustomer()) ?: $this->getHelper()->getQuoteDocCode($quote), 'CurrencyCode' => $this->limit($quote->getBaseCurrencyCode(), 3), 'Discount' => $hideDiscountAmount ? 0.0 : $store->roundPrice($address->getBaseDiscountAmount()), 'Addresses' => array(), 'Lines' => array()); if ($quote->getCustomerTaxvat()) { $request['BusinessIdentificationNo'] = $this->limit($quote->getCustomerTaxvat(), 25); } $request['Addresses'][] = $this->getOriginAddress('ORIGIN', $store); $request['Addresses'][] = $this->getAddress('DESTINATION', $address); $itemPriceIncludesTax = Mage::getStoreConfigFlag(Mage_Tax_Model_Config::CONFIG_XML_PATH_PRICE_INCLUDES_TAX, $store); foreach ($this->getHelper()->getActionableQuoteAddressItems($address) as $k => $item) { /** @var Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Quote_Address_Item $item */ $request['Lines'][] = array("LineNo" => $this->limit($k, 50), "ItemCode" => $this->limit($item->getSku(), 50), "Qty" => round(floatval($item->getQty()), 4), "Amount" => $store->roundPrice($item->getBaseRowTotal()) - $store->roundPrice($item->getBaseDiscountAmount()), "OriginCode" => "ORIGIN", "DestinationCode" => "DESTINATION", "Description" => $this->limit($item->getName(), 255), "TaxCode" => $this->limit($this->getHelper()->getProductTaxCode($item->getProduct()), 25), "Discounted" => $item->getBaseDiscountAmount() > 0.0, "TaxIncluded" => $itemPriceIncludesTax, "Ref1" => $this->limit($this->getHelper()->getQuoteItemRef1($item, $store), 250), "Ref2" => $this->limit($this->getHelper()->getQuoteItemRef2($item, $store), 250)); } $shippingPriceIncludesTax = Mage::getStoreConfigFlag(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX, $store); $request['Lines'][] = array("LineNo" => "SHIPPING", "ItemCode" => "SHIPPING", "Qty" => "1", "Amount" => $store->roundPrice($address->getBaseShippingAmount()) - $store->roundPrice($address->getBaseShippingDiscountAmount()), "OriginCode" => "ORIGIN", "DestinationCode" => "DESTINATION", "Description" => $this->limit("Shipping: " . $address->getShippingMethod(), 255), "TaxCode" => $this->limit($this->getHelper()->getShippingTaxCode($store), 25), "Discounted" => $address->getBaseShippingDiscountAmount() > 0.0, "TaxIncluded" => $shippingPriceIncludesTax, "Ref1" => $this->limit($address->getShippingMethod(), 250)); // TODO: Handle giftwrapping return $request; }