Example #1
1
 /**
  * validate
  *
  * @param Varien_Object $object Quote
  * @return boolean
  */
 public function validate(Varien_Object $object)
 {
     $all = $this->getAggregator() === 'all';
     $true = (bool) $this->getValue();
     $found = false;
     foreach ($object->getAllItems() as $item) {
         $found = $all;
         foreach ($this->getConditions() as $cond) {
             $validated = $cond->validate($item);
             if ($all && !$validated || !$all && $validated) {
                 $found = $validated;
                 break;
             }
         }
         if ($found && $true || !$true && $found) {
             break;
         }
     }
     // found an item and we're looking for existing one
     if ($found && $true) {
         return true;
     } elseif (!$found && !$true) {
         return true;
     }
     return false;
 }
Example #2
0
 /**
  * validate
  *
  * @param Varien_Object $object Quote
  * @return boolean
  */
 public function validate(Varien_Object $object)
 {
     if (!$this->getConditions()) {
         return false;
     }
     $attr = $this->getAttribute();
     $total = 0;
     if ($object->getAllItems()) {
         $validIds = array();
         foreach ($object->getAllItems() as $item) {
             if ($item->getProduct()->getTypeId() == 'configurable') {
                 $item->getProduct()->setTypeId('skip');
             }
             //can't use parent here
             if (Mage_SalesRule_Model_Rule_Condition_Product_Combine::validate($item)) {
                 $itemParentId = $item->getParentItemId();
                 if (is_null($itemParentId)) {
                     $validIds[] = $item->getItemId();
                 } else {
                     if (in_array($itemParentId, $validIds)) {
                         continue;
                     } else {
                         $validIds[] = $itemParentId;
                     }
                 }
                 $total += $item->getData($attr);
             }
             if ($item->getProduct()->getTypeId() === 'skip') {
                 $item->getProduct()->setTypeId('configurable');
             }
         }
     }
     return $this->validateAttribute($total);
 }
Example #3
0
 /**
  * Check availability of giftmessages for specified entity.
  *
  * @param string $type
  * @param Varien_Object $entity
  * @param Mage_Core_Model_Store|integer $store
  * @return boolean
  */
 public function isMessagesAvailable($type, Varien_Object $entity, $store = null)
 {
     if ($type == 'items') {
         $items = $entity->getAllItems();
         if (!is_array($items) || empty($items)) {
             return Mage::getStoreConfig(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, $store);
         }
         if ($entity instanceof Mage_Sales_Model_Quote) {
             $_type = $entity->getIsMultiShipping() ? 'address_item' : 'item';
         } else {
             $_type = 'order_item';
         }
         foreach ($items as $item) {
             if ($item->getParentItem()) {
                 continue;
             }
             if ($this->isMessagesAvailable($_type, $item, $store)) {
                 return true;
             }
         }
     } elseif ($type == 'item') {
         return $this->_getDependenceFromStoreConfig($entity->getProduct()->getGiftMessageAvailable(), $store);
     } elseif ($type == 'order_item') {
         return $this->_getDependenceFromStoreConfig($entity->getGiftMessageAvailable(), $store);
     } elseif ($type == 'address_item') {
         $storeId = is_numeric($store) ? $store : Mage::app()->getStore($store)->getId();
         if (!$this->isCached('address_item_' . $entity->getProductId())) {
             $this->setCached('address_item_' . $entity->getProductId(), Mage::getModel('Mage_Catalog_Model_Product')->setStoreId($storeId)->load($entity->getProductId())->getGiftMessageAvailable());
         }
         return $this->_getDependenceFromStoreConfig($this->getCached('address_item_' . $entity->getProductId()), $store);
     } else {
         return Mage::getStoreConfig(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ORDER, $store);
     }
     return false;
 }
Example #4
0
 /**
  * validate
  *
  * @param Varien_Object $object Quote
  * @return boolean
  */
 public function validate(Varien_Object $object)
 {
     $all = $this->getAttribute() === 'all';
     $found = false;
     foreach ($object->getAllItems() as $item) {
         $found = $all ? true : false;
         foreach ($this->getConditions() as $cond) {
             if ($all && !$cond->validate($item)) {
                 $found = false;
                 break;
             } elseif (!$all && $cond->validate($item)) {
                 $found = true;
                 break 2;
             }
         }
         if ($found && (bool) $this->getOperator()) {
             break;
         }
     }
     if ($found && (bool) $this->getOperator()) {
         // found an item and we're looking for existing one
         return true;
     } elseif (!$found && !(bool) $this->getOperator()) {
         // not found and we're making sure it doesn't exist
         return true;
     }
     return false;
 }
Example #5
0
 /**
  * @param Varien_Object $object
  *
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     /** @var Mage_Sales_Model_Order $object */
     if (!$object instanceof Mage_Sales_Model_Order) {
         return false;
     }
     $conditions = $this->getConditions();
     if (empty($conditions)) {
         return true;
     }
     $all = $this->getAggregator() === 'all';
     $true = (bool) $this->getValue();
     $found = false;
     foreach ($object->getAllItems() as $item) {
         /** @var Mage_Sales_Model_Order_Item $item */
         $found = $all;
         foreach ($conditions as $cond) {
             $validated = $cond->validate($item);
             if ($all !== $validated) {
                 $found = $validated;
                 break;
             }
         }
         if ($found) {
             break;
         }
     }
     // found an item and we're looking for existing one
     if ($found && $true) {
         return true;
     } elseif (!$found && !$true) {
         return true;
     }
     return false;
 }
Example #6
0
 /**
  * validate
  *
  * @param Varien_Object $object Quote
  * @return boolean
  */
 public function validate(Varien_Object $object)
 {
     if (!$this->getConditions()) {
         return false;
     }
     $attr = $this->getAttribute();
     $total = 0;
     if ($object->getAllItems()) {
         foreach ($object->getAllItems() as $item) {
             if ($item->getProductType() == 'configurable') {
                 continue;
             }
             //can't use parent here
             if (Mage_SalesRule_Model_Rule_Condition_Product_Combine::validate($item)) {
                 $total += $item->getData($attr);
             }
         }
     }
     return $this->validateAttribute($total);
 }
Example #7
0
 /**
  * validate
  *
  * @param Varien_Object $object Quote
  *
  * @return boolean
  */
 public function validate(Varien_Object $object)
 {
     if (!$this->getConditions()) {
         return false;
     }
     $attr = $this->getAttribute();
     $total = 0;
     foreach ($object->getAllItems() as $item) {
         if (parent::validate($item)) {
             $total += $item->getData($attr);
         }
     }
     return $this->validateAttribute($total);
 }
Example #8
0
 protected function setCarriergroupOnItems($carriergroupDetails, $productInRateResponse)
 {
     $rateItems = [];
     foreach ($productInRateResponse as $item) {
         $item = (array) $item;
         $rateItems[$item['sku']] = $item['qty'];
     }
     foreach ($this->rawRequest->getAllItems() as $quoteItem) {
         if (array_key_exists($quoteItem->getSku(), $rateItems)) {
             $quoteItem->setCarriergroupId($carriergroupDetails['carrierGroupId']);
             $quoteItem->setCarriergroup($carriergroupDetails['name']);
             if ($quoteItem->getQuoteItemId()) {
                 //need to work out how to distinguish between quote address items on multi address checkout
             }
             $this->carrierGroupHelper->saveCarrierGroupItem($quoteItem, $carriergroupDetails['carrierGroupId'], $carriergroupDetails['name']);
         }
     }
 }
 /**
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $all = $this->getAggregator() === 'all';
     $true = (bool) $this->getValue();
     $found = false;
     $globalFound = false;
     foreach ($object->getAllItems() as $item) {
         $found = $all;
         foreach ($this->getConditions() as $cond) {
             // fix bad product model
             $product = $item->getProduct();
             if ($product instanceof Mage_Catalog_Model_Product && is_null($product->getData($cond->getAttribute()))) {
                 $product->load($object->getProductId());
             }
             $validated = $cond->validate($item);
             if ($all && !$validated || !$all && $validated) {
                 $found = $validated;
                 break;
             }
         }
         if ($found) {
             Mage::registry('multifees_fee')->addFoundQuoteItemQty($item, $object->getId());
         }
         if ($found && $true || !$true && $found) {
             $globalFound = true;
             //break;
         }
     }
     if ($globalFound && $true) {
         // found an item and we're looking for existing one
         return true;
     } elseif (!$globalFound && !$true) {
         // not found and we're making sure it doesn't exist
         return true;
     }
     return false;
 }
Example #10
0
 public function collectRatesByAddress(Varien_Object $address, $limitCarrier = null)
 {
     $request = Mage::getModel('shipping/rate_request');
     $request->setAllItems($address->getAllItems());
     $request->setDestCountryId($address->getCountryId());
     $request->setDestRegionId($address->getRegionId());
     $request->setDestPostcode($address->getPostcode());
     $request->setPackageValue($address->getBaseSubtotal());
     $request->setPackageValueWithDiscount($address->getBaseSubtotalWithDiscount());
     $request->setPackageWeight($address->getWeight());
     $request->setFreeMethodWeight($address->getFreeMethodWeight());
     $request->setPackageQty($address->getItemQty());
     $request->setStoreId(Mage::app()->getStore()->getId());
     $request->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
     $request->setBaseCurrency(Mage::app()->getStore()->getBaseCurrency());
     $request->setPackageCurrency(Mage::app()->getStore()->getCurrentCurrency());
     $request->setLimitCarrier($limitCarrier);
     return $this->collectRates($request);
 }
Example #11
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';
 }