public function render(Varien_Object $row)
 {
     $html = '';
     $weekendsexclude = Mage::getStoreConfig('reminder/timesettings/weekendsexclude');
     // Obtain the order/reminder details
     $incrementid = $row->getIncrementId();
     $reminderorders = Mage::getModel('reminder/reminder')->getCollection()->addFieldToFilter('increment_id', $incrementid)->getItems();
     $reminderorder = reset($reminderorders);
     // Obtain the age
     $now = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp());
     $orderdate = new Zend_Date($row->getCreatedAt(), 'yyyy-MM-dd');
     $age = $now->sub($orderdate)->toValue();
     $days = ceil($age / 60 / 60 / 24);
     // Obtain the age (weekend excluded)
     if ($weekendsexclude == 'enabled') {
         $start_date = new Zend_Date($row->getCreatedAt(), 'yyyy-MM-dd');
         $end_date = new Zend_Date($start_date);
         $dayscounter = $days;
         $weekenddays = 0;
         while ($dayscounter > 0) {
             $weekdaydigit = $end_date->toValue(Zend_Date::WEEKDAY_DIGIT);
             if ($weekdaydigit == 0 || $weekdaydigit == 6) {
                 $weekenddays++;
             }
             $end_date->addDay(1);
             $dayscounter--;
         }
         $days = $days - $weekenddays;
     }
     // Display the HTML
     $html .= $reminderorder->getReminders();
     $html .= ' (age: ' . $days . ')';
     $html .= '<br/><a href="' . $this->getUrl('*/*/manipulate/option/add/id/' . $row->getIncrementId()) . '">' . Mage::helper('reminder')->__('add') . ' 1</a>';
     $html .= '<br/><a href="' . $this->getUrl('*/*/manipulate/option/sub/id/' . $row->getIncrementId()) . '">' . Mage::helper('reminder')->__('remove') . ' 1</a>';
     $html .= '<br/><a href="' . $this->getUrl('*/*/manipulate/option/reset/id/' . $row->getIncrementId()) . '">' . Mage::helper('reminder')->__('reset to') . ' 0</a>';
     return $html;
 }
Example #2
0
 protected function _prepareCollection()
 {
     $helper = Mage::helper('mandrill');
     $mail = $helper->api()->setApiKey($helper->getApiKey());
     $emails = $mail->usersSenders();
     if ($emails !== FALSE) {
         $_emails = array();
         foreach ($emails as $email) {
             $email = new Varien_Object((array) $email);
             $_emails[] = array('email' => $email->getAddress(), 'sent' => $email->getSent(), 'rejects' => $email->getRejects(), 'complaints' => $email->getComplaints(), 'unsubs' => $email->getUnsubs(), 'opens' => $email->getUniqueOpens(), 'clicks' => $email->getUniqueClicks(), 'hard_bounces' => $email->getHardBounces(), 'soft_bounces' => $email->getSoftBounces(), 'created_at' => $email->getCreatedAt());
         }
         $collection = Mage::getModel('mandrill/customcollection', array($_emails));
     } else {
         $collection = Mage::getModel('mandrill/customcollection', array(array()));
     }
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
 /**
  * Return an internal reference ID for Amazon API transactions
  */
 protected function _getMagentoReferenceId(Varien_Object $payment)
 {
     $order = $payment->getOrder();
     return $order->getIncrementId() . '-' . strtotime($payment->getCreatedAt());
 }
Example #4
0
 public function orderSaveAfter($event)
 {
     $order = $event->getOrder();
     $origData = new Varien_Object($order->getOrigData());
     $this->_getCacheCollection()->expirePeriodFor($origData->getCreatedAt(), $origData->getUpdatedAt(), $order->getUpdatedAt());
 }
Example #5
0
 protected function _getValue(Varien_Object $row)
 {
     $date = $row->getCreatedAt();
     $datetime = new DateTime($date);
     return $datetime->format('m/d/Y H:i:s');
 }
 /**
  * calculate earning for quote/order item
  * 
  * @param Varien_Object $item
  * @param int $customerGroupId
  * @param int $websiteId
  * @param string $date
  * @return int
  */
 public function getCatalogItemEarningPoints($item, $customerGroupId = null, $websiteId = null, $date = null)
 {
     $product = Mage::getModel('catalog/product')->load($item->getProductId());
     //webpos
     $customerId = Mage::getSingleton('checkout/session')->getData('webpos_customerid');
     if ($customerId) {
         $customerGroupId = Mage::getModel('customer/customer')->load($customerId)->getGroupId();
     } else {
         $customerGroupId = Mage_Customer_Model_Group::NOT_LOGGED_IN_ID;
     }
     if (is_null($websiteId)) {
         $websiteId = Mage::app()->getStore($item->getStoreId())->getWebsiteId();
     }
     if (is_null($date)) {
         $date = date('Y-m-d', strtotime($item->getCreatedAt()));
     }
     $cacheKey = "catalog_item_earning:{$item->getId()}:{$customerGroupId}:{$websiteId}";
     if ($this->hasCache($cacheKey)) {
         return $this->getCache($cacheKey);
     }
     $points = 0;
     $collectionKey = "catalog_earning_collection:{$customerGroupId}:{$websiteId}";
     if (!$this->hasCache($collectionKey)) {
         $rules = Mage::getResourceModel('rewardpointsrule/earning_catalog_collection')->setAvailableFilter($customerGroupId, $websiteId, $date);
         foreach ($rules as $rule) {
             $rule->afterLoad();
         }
         $this->saveCache($collectionKey, $rules);
     } else {
         $rules = $this->getCache($collectionKey);
     }
     if ($item->getHasChildren() && $item->isChildrenCalculated()) {
         $price = 0;
         $profit = 0;
         foreach ($item->getChildren() as $child) {
             $price += $child->getQty() * $child->getBasePrice();
             $profit += $child->getQty() * ($child->getBasePrice() - $child->getBaseCost());
         }
     } else {
         $price = $item->getBasePrice();
         if (!$price && $item->getPrice()) {
             $price = $item->getPrice() / Mage::app()->getStore($item->getStoreId())->convertPrice(1);
         }
         $profit = $price - $item->getBaseCost();
     }
     foreach ($rules as $rule) {
         if ($rule->validate($product)) {
             $points += $this->calcCatalogPoint($rule->getSimpleAction(), $rule->getPointsEarned(), $price, $profit, $rule->getMoneyStep(), $rule->getMaxPointsEarned());
             if ($rule->getStopRulesProcessing()) {
                 break;
             }
         }
     }
     $this->saveCache($cacheKey, $points * $item->getQty());
     return $this->getCache($cacheKey);
 }
Example #7
0
 /**
  * Define the enqueue XML data
  *
  * @param Varien_Object $order
  */
 private function enfileirarData($order)
 {
     $this->_resetData();
     //Pega os dados do cliente
     $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
     //Define os dados da cobrança
     $this->xmlCompradorNome = (string) $order->getBillingAddress()->getFirstname() . ' ' . $order->getBillingAddress()->getLastname();
     $customerDocs = explode(",", Mage::getStoreConfig('allpago/fcontrol/campo_documento'));
     $cpfLog = null;
     foreach ($customerDocs as $customerDoc) {
         $metodo = 'get' . ucfirst($customerDoc);
         if (!$this->xmlCompradorCpfCnpj && $customer->{$metodo}()) {
             $this->xmlCompradorCpfCnpj = (string) preg_replace('/[^0-9]/', '', $customer->{$metodo}());
         }
         if ($customer->{$metodo}()) {
             $cpfLog .= '<pre>' . print_r($customer->getData(), true) . '<br/>Método: ' . $metodo . ' ( ' . $customer->{$metodo}() . ' )</pre>';
         }
     }
     if (!$this->xmlCompradorCpfCnpj) {
         Mage::throwException('CPF não encontrado' . $cpfLog);
     }
     $this->xmlCompradorSexo = (string) 'M';
     // @todo: Pegar esta informação do Magento
     $this->xmlCompradorDataNascimento = (string) '1900-01-01';
     // @todo: Pegar esta informação do Magento
     $this->xmlCompradorDddTelefone = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getBillingAddress()->getTelephone())), 0, 2);
     $this->xmlCompradorNumeroTelefone = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getBillingAddress()->getTelephone())), 2, 9);
     $this->xmlCompradorDddCelular = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getBillingAddress()->getTelephone())), 0, 2);
     // @todo: Pegar esta informação do Magento / Community e o Enterprise
     $this->xmlCompradorNumeroCelular = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getBillingAddress()->getTelephone())), 2, 9);
     // @todo: Pegar esta informação do Magento / Community e o Enterprise
     $this->xmlCompradorIP = (string) $order->getRemoteIp();
     $this->xmlCompradorEmail = (string) $order->getCustomerEmail();
     $this->xmlCompradorEnderecoCep = (string) str_replace(' ', '', preg_replace('/[-.]*/', '', $order->getBillingAddress()->getPostcode()));
     $this->xmlCompradorEnderecoRua = (string) $order->getBillingAddress()->getStreet(1);
     $this->xmlCompradorEnderecoNumero = (string) $order->getBillingAddress()->getStreet(2);
     $this->xmlCompradorEnderecoComplemento = (string) Mage::helper('core/string')->truncate($order->getBillingAddress()->getStreet(3), 100);
     $this->xmlCompradorEnderecoBairro = (string) $order->getBillingAddress()->getStreet(4);
     $this->xmlCompradorEnderecoCidade = (string) $order->getBillingAddress()->getCity();
     $region = "";
     $directoryRegion = Mage::getResourceModel('directory/region_collection');
     $directoryRegion->getSelect()->reset()->from(array('main_table' => $directoryRegion->getMainTable()), 'default_name');
     $directoryRegion->addFieldToFilter('country_id', 'BR')->addFieldToFilter('region_id', $order->getBillingAddress()->getRegionId());
     $billingRegion = $directoryRegion->getResource()->getReadConnection()->fetchOne($directoryRegion->getSelect());
     $this->xmlCompradorEnderecoEstado = (string) $billingRegion;
     //Define os dados de entrega
     $this->xmlEntregaNome = (string) ($order->getShippingAddress()->getFirstname() . ' ' . $order->getShippingAddress()->getLastname());
     $customerDocs = explode(",", Mage::getStoreConfig('allpago/fcontrol/campo_documento'));
     $this->xmlEntregaCpfCnpj = null;
     foreach ($customerDocs as $customerDoc) {
         $metodo = 'get' . ucfirst($customerDoc);
         if (!$this->xmlEntregaCpfCnpj && $order->getShippingAddress()->{$metodo}()) {
             $this->xmlEntregaCpfCnpj = (string) preg_replace('/[^0-9]/', '', $order->getShippingAddress()->{$metodo}());
         }
     }
     $this->xmlEntregaCpfCnpj = $this->xmlEntregaCpfCnpj ? $this->xmlEntregaCpfCnpj : $this->xmlCompradorCpfCnpj;
     $this->xmlEntregaSexo = (string) 'M';
     // @todo: Pegar esta informação do Magento
     $this->xmlEntregaDataNascimento = (string) '1900-01-01';
     // @todo: Pegar esta informação do Magento
     $this->xmlEntregaDddTelefone = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getShippingAddress()->getTelephone())), 0, 2);
     $this->xmlEntregaNumeroTelefone = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getShippingAddress()->getTelephone())), 2, 9);
     $this->xmlEntregaDddCelular = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getBillingAddress()->getTelephone())), 0, 2);
     // @todo: Pegar esta informação do Magento / Community e o Enterprise
     $this->xmlEntregaNumeroCelular = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getShippingAddress()->getTelephone())), 2, 9);
     // @todo: Pegar esta informação do Magento / Community e o Enterprise
     $this->xmlEntregaEnderecoCep = (string) str_replace(' ', '', preg_replace('/[-.]*/', '', $order->getShippingAddress()->getPostcode()));
     $this->xmlEntregaEnderecoRua = (string) $order->getShippingAddress()->getStreet(1);
     $this->xmlEntregaEnderecoNumero = (string) $order->getShippingAddress()->getStreet(2);
     $this->xmlEntregaEnderecoComplemento = (string) Mage::helper('core/string')->truncate($order->getShippingAddress()->getStreet(3), 100);
     $this->xmlEntregaEnderecoBairro = (string) $order->getShippingAddress()->getStreet(4);
     $this->xmlEntregaEnderecoCidade = (string) $order->getShippingAddress()->getCity();
     $directoryRegion = Mage::getResourceModel('directory/region_collection');
     $directoryRegion->getSelect()->reset()->from(array('main_table' => $directoryRegion->getMainTable()), 'default_name');
     $directoryRegion->addFieldToFilter('country_id', 'BR')->addFieldToFilter('region_id', $order->getShippingAddress()->getRegionId());
     $shippingRegion = $directoryRegion->getResource()->getReadConnection()->fetchOne($directoryRegion->getSelect());
     $this->xmlEntregaEnderecoEstado = (string) $shippingRegion;
     //Define os dados dos produtos
     $totalItems = 0;
     $items = $order->getAllItems();
     $this->xmlPedidoProdutos = array();
     foreach ($items as $item) {
         $this->xmlPedidoProdutos[] = array('Codigo' => (string) $item->getProductId(), 'Descricao' => (string) $item->getName(), 'Quantidade' => (string) $item->getQtyOrdered(), 'ValorUnitario' => (string) $item->getPrice() * 100, 'ListaDeCasamento' => (string) false, 'ParaPresente' => (string) false);
         $totalItems += $item->getQtyOrdered();
     }
     //Define os dados do pagamento
     $this->xmlPedidoPagamentos = array('MetodoPagamento' => (string) 'CartaoCredito', 'Valor' => (string) ($order->getGrandTotal() * 100), 'NumeroParcelas' => (string) 1);
     //Define os dados dos pedido
     $this->xmlPedidoCodigoPedido = (string) $order->getId();
     $dataCompra = new DateTime($order->getCreatedAt());
     $dataCompra->setTimezone(new DateTimeZone('America/Sao_Paulo'));
     $this->xmlPedidoDataCompra = (string) $dataCompra->format('Y-m-d\\TH:i:s');
     $this->xmlPedidoQuantidadeItensDistintos = (string) count($items);
     $this->xmlPedidoQuantidadeTotalItens = (string) $totalItems;
     $this->xmlPedidoValorTotalCompra = (string) ($order->getGrandTotal() * 100);
     $this->xmlPedidoValorTotalFrete = (string) ($order->getPayment()->getShippingAmount() * 100);
     $this->xmlPedidoPrazoEntregaDias = (string) '0';
     $this->xmlPedidoCanalVenda = (string) 'Loja Virtual';
 }
Example #8
0
 public function render(Varien_Object $row)
 {
     /** @var $row Inchoo_Fiskalizacija_Model_Invoice */
     $dt = new DateTime($row->getCreatedAt());
     return $dt->format('d.m.Y H:i:s');
 }