/** * Validate if qoute customer is assigned to role segments * * @param Mage_Sales_Model_Quote_Address|Varien_Object $object * @return bool */ public function validate(Varien_Object $object) { $subscriptionId = $object->getQuote()->getSubscriptionId(); $quoteCount = 1; if (!$subscriptionId) { $isSubscription = Mage::getSingleton('adyen_subscription/product_observer')->isQuoteAdyenSubscription($object->getQuote()); if (!$isSubscription) { return false; } } else { $pastOrders = Mage::getResourceModel('adyen_subscription/subscription_quote_collection')->addFieldToFilter('order_id', array('notnull' => true))->addFieldToFilter('subscription_id', $subscriptionId); $quoteCount += $pastOrders->getSize(); } return $this->validateAttribute($quoteCount); }
/** * Validate Address Rule Condition * * @param Varien_Object $object * @return bool */ public function validate(Varien_Object $object) { $address = $object; if (!$address instanceof Mage_Sales_Model_Quote_Address) { if ($object->getQuote()->isVirtual()) { $address = $object->getQuote()->getBillingAddress(); } else { $address = $object->getQuote()->getShippingAddress(); } } if ('payment_method' == $this->getAttribute() && !$address->hasPaymentMethod()) { $address->setPaymentMethod($object->getQuote()->getPayment()->getMethod()); } return parent::validate($address); }
/** * Validate Address Rule Condition * * @param Varien_Object $object * @return bool */ public function validate(Varien_Object $object) { $quote = $object; if (!$quote instanceof Mage_Sales_Model_Quote) { $quote = $object->getQuote(); } $num = 0; if ($quote->getCustomerId()) { $resource = Mage::getSingleton('core/resource'); $db = $resource->getConnection('core_read'); $select = $db->select()->from(array('o' => $resource->getTableName('sales/order')), array())->where('o.customer_id = ?', $quote->getCustomerId())->where('o.status = ?', 'complete'); if ('order_num' == $this->getAttribute()) { $select->from(null, array(new Zend_Db_Expr('COUNT(*)'))); } elseif ('sales_amount' == $this->getAttribute()) { $select->from(null, array(new Zend_Db_Expr('SUM(o.base_grand_total)'))); } // elseif ('prods_qty' == $this->getAttribute()){ // // $select->joinInner(array('i'=>$resource->getTableName('sales/order_item')), 'o.entity_id=i.order_id', array(new Zend_Db_Expr('SUM(i.qty_ordered)'))) // (null, array(new Zend_Db_Expr('SUM(o.base_grand_total)'))) // } $num = $db->fetchOne($select); } return $this->validateAttribute($num); }
/** * 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->getQuote()->getAllVisibleItems() 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; } } if ($found && $true) { // found an item and we're looking for existing one return true; } elseif (!$found && !$true) { // not found and we're making sure it doesn't exist return true; } return false; }
public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $this->quote = $data->getQuote(); return $this; }
public function validate(Varien_Object $object) { $quote = $object; if (!$quote instanceof Mage_Sales_Model_Quote) { $quote = $object->getQuote(); } $num = Mage::getModel('amacart/history')->getRecoveredNumberByEmail($quote->getCustomerEmail(), '6month'); return $this->validateAttribute($num); }
/** * Validate if quote customer is assigned to role segments * * @param Mage_Sales_Model_Quote_Address|Varien_Object $object * @return bool */ public function validate(Varien_Object $object) { $isSubscription = Mage::getSingleton('adyen_subscription/product_observer')->isQuoteAdyenSubscription($object->getQuote()); if (!$isSubscription) { return false; } foreach ($object->getQuote()->getAllVisibleItems() as $quoteItem) { $subscriptionId = $quoteItem->getData('_adyen_subscription'); if (!$subscriptionId) { continue; } $validated = $this->validateAttribute($subscriptionId); if ($validated) { return true; } } return false; }
/** * 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->getQuote()->getAllItems() as $item) { if (parent::validate($item)) { $total += $item->getData($attr); } } return $this->validateAttribute($total); }
public function validate(Varien_Object $object) { if ($object instanceof Rewardpoints_Model_Quote && !$object->getQuote()) { $object->setQuote($object); } $address = $object; if (!$address instanceof Mage_Sales_Model_Quote_Address) { if ($object->getQuote()->isVirtual()) { $address = $object->getQuote()->getBillingAddress(); } else { $address = $object->getQuote()->getShippingAddress(); } } $address->setBaseSubtotalIncTax($address->getBaseSubtotal() + $address->getBaseTaxAmount()); return parent::validate($object); }
/** * validate * * @param Varien_Object $object Quote * @return boolean */ public function validate(Varien_Object $object) { if (!$this->getConditions()) { return false; } // $value = $this->getValue(); // $aggregatorArr = explode('/', $this->getAggregator()); // $this->setValue((int)$aggregatorArr[0])->setAggregator($aggregatorArr[1]); $attr = $this->getAttribute(); $total = 0; foreach ($object->getQuote()->getAllItems() as $item) { if (parent::validate($item)) { $total += $item->getData($attr); } } // $this->setAggregator(join('/', $aggregatorArr))->setValue($value); return $this->validateAttribute($total); }
/** * validate * * @param Varien_Object $object Quote * @return boolean */ public function validate(Varien_Object $object) { if (!$this->getConditions()) { return false; } // Fix a bug with the underlying combine condition check $value = $this->getValue(); $this->setValue(true); $total = 0; foreach ($object->getQuote()->getAllVisibleItems() as $item) { if (Mage_SalesRule_Model_Rule_Condition_Product_Combine::validate($item)) { $total += $item->getData($this->getAttribute()); } } // Fix a bug with the underlying combine condition check $this->setValue($value); return $this->validateAttribute($total); }
public function validate(Varien_Object $object) { $quote = $object; if (!$quote instanceof Mage_Sales_Model_Quote) { $quote = $object->getQuote(); } // order history conditions are valid for customers only, not for visitors. $id = $quote->getCustomerId(); if (!$id) { return false; } $condArray = array(); foreach ($this->getConditions() as $condObj) { $condArray[] = $condObj->validate($object); } $fieldName = $this->getAttributeElement()->getValue(); $v = Mage::getSingleton('amrules/calculator')->getSingleTotalField($id, $fieldName, $condArray, $this->getAggregator()); return $this->validateAttribute($v); }
/** * Validate items total amount or total qty * * @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->getQuote()->getAllItems() as $item) { // fix magento bug if ($item->getParentItemId()) { continue; } // for bundle we need to add a loop here // if we treat them as set of separate items if (@Amasty_Rules_Model_SalesRule_Rule_Condition_Product_Combine::validate($item)) { $total += $item->getData($attr); } } return $this->validateAttribute($total); }
/** * Validate Address Rule Condition * * @param Varien_Object $object * @return bool */ public function validate(Varien_Object $object) { $customer = $object; if (!$customer instanceof Mage_Customer_Model_Customer) { $customer = $object->getQuote()->getCustomer(); $attr = $this->getAttribute(); if ($attr != 'entity_id' && !$customer->getData($attr)) { $address = $object->getQuote()->getBillingAddress(); $customer->setData($attr, $address->getData($attr)); } } return parent::validate($customer); }
/** * Validate if qoute customer is assigned to role segments * * @param Mage_Sales_Model_Quote_Address $object * @return bool */ public function validate(Varien_Object $object) { $customer = null; if ($object->getQuote()) { $customer = $object->getQuote()->getCustomer(); } if (!$customer) { return false; } $segments = Mage::getSingleton('enterprise_customersegment/customer')->getCustomerSegmentIdsForWebsite($customer->getId(), $object->getQuote()->getStore()->getWebsite()->getId()); return $this->validateAttribute($segments); }
/** * Validate Address Rule Condition * * @param Varien_Object $object * @return bool */ public function validate(Varien_Object $object) { $customer = $object; if (!$customer instanceof Mage_Customer_Model_Customer) { $customer = $object->getQuote()->getCustomer(); $attr = $this->getAttribute(); if ($attr == 'membership_days') { $customer->setData($attr, Mage::helper('amrules')->getMembership($customer->getCreatedAt())); } if ($attr != 'entity_id' && !$customer->getData($attr)) { $address = $object->getQuote()->getBillingAddress(); $customer->setData($attr, $address->getData($attr)); } } return parent::validate($customer); }
/** * Import totals information from google request to quote address * * @param Varien_Object $qAddress */ protected function _importGoogleTotals($qAddress) { $quote = $qAddress->getQuote(); $qAddress->setTaxAmount($this->_reCalculateToStoreCurrency($this->getData('root/order-adjustment/total-tax/VALUE'), $quote)); $qAddress->setBaseTaxAmount($this->getData('root/order-adjustment/total-tax/VALUE')); $prefix = 'root/order-adjustment/shipping/'; if ($shipping = $this->getData($prefix . 'carrier-calculated-shipping-adjustment')) { $method = 'googlecheckout_carrier'; } elseif ($shipping = $this->getData($prefix . 'merchant-calculated-shipping-adjustment')) { $method = 'googlecheckout_merchant'; } elseif ($shipping = $this->getData($prefix . 'flat-rate-shipping-adjustment')) { $method = 'googlecheckout_flatrate'; } elseif ($shipping = $this->getData($prefix . 'pickup-shipping-adjustment')) { $method = 'googlecheckout_pickup'; } if (!empty($method)) { Mage::getSingleton('tax/config')->setShippingPriceIncludeTax(false); $rate = Mage::getModel('sales/quote_address_rate')->setCode($method)->setPrice($shipping['shipping-cost']['VALUE']); $qAddress->addShippingRate($rate)->setShippingMethod($method)->setShippingDescription($shipping['shipping-name']['VALUE']); /*if (!Mage::helper('tax')->shippingPriceIncludesTax($quote->getStore())) { $includingTax = Mage::helper('tax')->getShippingPrice($excludingTax, true, $qAddress, $quote->getCustomerTaxClassId()); $shippingTax = $includingTax - $excludingTax; $qAddress->setShippingTaxAmount($this->_reCalculateToStoreCurrency($shippingTax, $quote)) ->setBaseShippingTaxAmount($shippingTax) ->setShippingInclTax($includingTax) ->setBaseShippingInclTax($this->_reCalculateToStoreCurrency($includingTax, $quote)); } else { if ($method == 'googlecheckout_carrier') { $qAddress->setShippingTaxAmount(0) ->setBaseShippingTaxAmount(0); } }*/ } else { $qAddress->setShippingMethod(null); } $qAddress->setGrandTotal($this->_reCalculateToStoreCurrency($this->getData('root/order-total/VALUE'), $quote)); $qAddress->setBaseGrandTotal($this->getData('root/order-total/VALUE')); }
/** * Validate Address Rule Condition * * @param Varien_Object $object * @return bool */ public function validate(Varien_Object $object) { $address = $object; if (!$address instanceof Mage_Sales_Model_Quote_Address) { if ($object->getQuote()->isVirtual()) { $address = $object->getQuote()->getBillingAddress(); } else { $address = $object->getQuote()->getShippingAddress(); } } return parent::validate($address); }
/** * Validate if qoute customer is assigned to role segments * * @param Mage_Sales_Model_Quote_Address $object * @return bool */ public function validate(Varien_Object $object) { if (!Mage::helper('enterprise_customersegment')->isEnabled()) { return false; } $customer = null; if ($object->getQuote()) { $customer = $object->getQuote()->getCustomer(); } if (!$customer) { return false; } $quoteWebsiteId = $object->getQuote()->getStore()->getWebsite()->getId(); if (!$customer->getId()) { $visitorSegmentIds = Mage::getSingleton('customer/session')->getCustomerSegmentIds(); if (is_array($visitorSegmentIds) && isset($visitorSegmentIds[$quoteWebsiteId])) { $segments = $visitorSegmentIds[$quoteWebsiteId]; } else { $segments = array(); } } else { $segments = Mage::getSingleton('enterprise_customersegment/customer')->getCustomerSegmentIdsForWebsite($customer->getId(), $quoteWebsiteId); } return $this->validateAttribute($segments); }
public function createOrder(Varien_Object $payment, $amount, $authorize) { $store_id = Mage::app()->getStore()->getStoreId(); $logger = Mage::helper('worldpay/logger'); if ($payment->getOrder()) { $orderId = $payment->getOrder()->getIncrementId(); $order = $payment->getOrder(); } else { $quote = $payment->getQuote(); $orderId = $quote->getReservedOrderId(); $quote->save(); } $session = Mage::getSingleton('core/session'); $token = $session->getData('payment_token'); $savedCard = $session->getData('saved_card'); $logger->log('Begin create order'); $session->setData('wp_3dsSuccess', false); $session->setData('wp_orderCode', false); $worldpay = $this->setupWorldpay(); $checkout = Mage::getSingleton('checkout/session')->getQuote(); $billing = $checkout->getBillingAddress(); $order_description = Mage::getStoreConfig('payment/worldpay/description', $store_id); if (!$order_description) { $order_description = "Order"; } $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode(); $name = $billing->getName(); $billing_address = array("address1" => $billing->getStreet(1), "address2" => $billing->getStreet(2), "address3" => $billing->getStreet(3), "postalCode" => $billing->getPostcode(), "city" => $billing->getCity(), "state" => "", "countryCode" => $billing->getCountry()); try { $mode = Mage::getStoreConfig('payment/worldpay_mode', Mage::app()->getStore()->getStoreId()); $settlementCurrency = Mage::getStoreConfig('payment/worldpay/settlementcurrency', Mage::app()->getStore()->getStoreId()); $createOrderRequest = array('token' => $token, 'orderDescription' => $order_description, 'amount' => $amount * 100, 'currencyCode' => $currency_code, 'name' => $name, 'billingAddress' => $billing_address, 'customerOrderCode' => $orderId, 'settlementCurrency' => $settlementCurrency, 'successUrl' => Mage::getUrl('worldpay/apm/success', array('_secure' => true)), 'pendingUrl' => Mage::getUrl('worldpay/apm/pending', array('_secure' => true)), 'failureUrl' => Mage::getUrl('worldpay/apm/failure', array('_secure' => true)), 'cancelUrl' => Mage::getUrl('worldpay/apm/cancel', array('_secure' => true))); $logger->log('Order Request: ' . print_r($createOrderRequest, true)); $response = $worldpay->createApmOrder($createOrderRequest); $logger->log('Order Response: ' . print_r($response, true)); if ($response['paymentStatus'] === 'SUCCESS') { $this->setStore($payment->getOrder()->getStoreId()); $logger->log('Order: ' . $response['orderCode'] . ' SUCCESS'); $payment->setStatus(self::STATUS_APPROVED); $payment->setAmount($amount); $payment->setLastTransId($orderId); $payment->setTransactionId($response['orderCode']); $payment->setAdditionalInformation("worldpayOrderCode", $response['orderCode']); $payment->setShouldCloseParentTransaction(1)->setIsTransactionClosed(1)->registerCaptureNotification($amount); } else { if ($response['paymentStatus'] == 'PRE_AUTHORIZED') { $logger->log('Order: ' . $response['orderCode'] . ' PRE_AUTHORIZED'); $payment->setAmount($amount); $payment->setAdditionalInformation("worldpayOrderCode", $response['orderCode']); $payment->setLastTransId($orderId); $payment->setTransactionId($response['orderCode']); $payment->setIsTransactionClosed(false); $session->setData('wp_redirectURL', $response['redirectURL']); $session->setData('wp_orderCode', $response['orderCode']); } else { if (isset($response['paymentStatusReason'])) { throw new Exception($response['paymentStatusReason']); } else { throw new Exception(print_r($response, true)); } } } } catch (Exception $e) { $payment->setStatus(self::STATUS_ERROR); $payment->setAmount($amount); $payment->setLastTransId($orderId); $logger->log($e->getMessage()); Mage::throwException('Payment failed, please try again later ' . $e->getMessage()); } return $this; }
public function createOrder(Varien_Object $payment, $amount, $authorize) { $store_id = Mage::app()->getStore()->getStoreId(); if ($payment->getOrder()) { $orderId = $payment->getOrder()->getIncrementId(); } else { $orderId = $payment->getQuote()->getIncrementId(); // $order = $payment->getOrder()) } $logger = Mage::helper('worldpay/logger'); $session = Mage::getSingleton('core/session'); $token = $session->getData('payment_token'); $savedCard = $session->getData('saved_card'); $logger->log('Begin create order'); $session->setData('wp_3dsSuccess', false); $session->setData('wp_orderCode', false); $worldpay = $this->setupWorldpay(); if (Mage::app()->getStore()->isAdmin()) { $checkout = Mage::getSingleton('adminhtml/session_quote')->getQuote(); } else { $checkout = Mage::getSingleton('checkout/session')->getQuote(); } $billing = $checkout->getBillingAddress(); $order_description = Mage::getStoreConfig('payment/' . $this->_code . '/description', $store_id); if (!$order_description) { $order_description = "Order"; } $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode(); $name = $billing->getName(); $billing_address = array("address1" => $billing->getStreet(1), "address2" => $billing->getStreet(2), "address3" => $billing->getStreet(3), "postalCode" => $billing->getPostcode(), "city" => $billing->getCity(), "state" => "", "countryCode" => $billing->getCountry()); try { $mode = Mage::getStoreConfig('payment/worldpay_mode', Mage::app()->getStore()->getStoreId()); $orderType = 'ECOM'; $threeDS = Mage::getStoreConfig('payment/worldpay_cc/use3ds', Mage::app()->getStore()->getStoreId()); if (Mage::app()->getStore()->isAdmin()) { $orderType = 'MOTO'; $threeDS = false; } if ($threeDS && $mode == 'Test Mode') { $name = '3D'; } $settlementCurrency = Mage::getStoreConfig('payment/worldpay_cc/settlementcurrency', Mage::app()->getStore()->getStoreId()); $createOrderRequest = array('token' => $token, 'orderDescription' => $order_description, 'amount' => $amount * 100, 'currencyCode' => $currency_code, 'name' => $name, 'orderType' => $orderType, 'is3DSOrder' => $threeDS, 'authoriseOnly' => $authorize, 'billingAddress' => $billing_address, 'customerOrderCode' => $orderId, 'settlementCurrency' => $settlementCurrency); $logger->log('Order Request: ' . print_r($createOrderRequest, true)); $response = $worldpay->createOrder($createOrderRequest); $logger->log('Order Response: ' . print_r($response, true)); if ($response['paymentStatus'] === 'SUCCESS') { $this->setStore($payment->getOrder()->getStoreId()); $logger->log('Order: ' . $response['orderCode'] . ' SUCCESS'); $payment->setStatus(self::STATUS_APPROVED); $payment->setAmount($amount); $payment->setLastTransId($orderId); $payment->setTransactionId($response['orderCode']); $payment->setAdditionalInformation("worldpayOrderCode", $response['orderCode']); // $formatedPrice = $order->getBaseCurrency()->formatTxt($amount); $payment->setShouldCloseParentTransaction(1)->setIsTransactionClosed(1)->registerCaptureNotification($amount); } else { if ($response['paymentStatus'] == 'AUTHORIZED') { $this->setStore($payment->getOrder()->getStoreId()); $logger->log('Order: ' . $response['orderCode'] . ' AUTHORIZED'); $payment->setIsTransactionClosed(0); $payment->setSkipOrderProcessing(true); $payment->setStatus(self::STATUS_APPROVED); $payment->setAmount($amount); $payment->setAdditionalInformation("worldpayOrderCode", $response['orderCode']); $payment->setLastTransId($orderId); $payment->setTransactionId($response['orderCode']); } else { if ($response['is3DSOrder']) { $session = Mage::getSingleton('core/session'); $logger->log('Starting 3DS Order: ' . $response['orderCode']); $session->setData('wp_3dsSuccess', false); $session->setData('wp_redirectURL', $response['redirectURL']); $session->setData('wp_oneTime3DsToken', $response['oneTime3DsToken']); $session->setData('wp_orderCode', $response['orderCode']); // IF normal checkout $currentUrl = Mage::helper('core/url')->getCurrentUrl(); $url = Mage::getSingleton('core/url')->parseUrl($currentUrl); $path = $url->getPath(); if (strpos($path, 'onepage') === false) { Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('worldpay/threeDS')); Mage::app()->getResponse()->sendResponse(); } else { echo 'window.WorldpayMagento.loadThreeDS("' . Mage::getUrl('worldpay/threeDS') . '")'; } exit; } else { if (isset($response['paymentStatusReason'])) { throw new Exception($response['paymentStatusReason']); } else { throw new Exception(print_r($response, true)); } } } } } catch (Exception $e) { $payment->setStatus(self::STATUS_ERROR); $payment->setAmount($amount); $payment->setLastTransId($orderId); $logger->log($e->getMessage()); Mage::throwException('Payment failed, please try again later ' . $e->getMessage()); } return $this; }
/** * Import totals information from google request to quote address * * @param Varien_Object $qAddress */ protected function _importGoogleTotals($qAddress) { $quote = $qAddress->getQuote(); $qAddress->setTaxAmount($this->_reCalculateToStoreCurrency($this->getData('root/order-adjustment/total-tax/VALUE'), $quote)); $qAddress->setBaseTaxAmount($this->getData('root/order-adjustment/total-tax/VALUE')); $method = null; $prefix = 'root/order-adjustment/shipping/'; if (null !== ($shipping = $this->getData($prefix . 'carrier-calculated-shipping-adjustment'))) { $method = 'googlecheckout_carrier'; } else { if (null !== ($shipping = $this->getData($prefix . 'merchant-calculated-shipping-adjustment'))) { $method = $this->_getShippingMethodByName($shipping['shipping-name']['VALUE']); if ($method === false) { $method = 'googlecheckout_merchant'; } } else { if (null !== ($shipping = $this->getData($prefix . 'flat-rate-shipping-adjustment'))) { $method = 'googlecheckout_flatrate'; } else { if (null !== ($shipping = $this->getData($prefix . 'pickup-shipping-adjustment'))) { $method = 'googlecheckout_pickup'; } } } } if ($method) { Mage::getSingleton('Mage_Tax_Model_Config')->setShippingPriceIncludeTax(false); $rate = $this->_createShippingRate($method)->setMethodTitle($shipping['shipping-name']['VALUE'])->setPrice($shipping['shipping-cost']['VALUE']); $qAddress->addShippingRate($rate)->setShippingMethod($method)->setShippingDescription($shipping['shipping-name']['VALUE']); // We get from Google price with discounts applied via merchant calculations $qAddress->setShippingAmountForDiscount(0); /*if (!Mage::helper('Mage_Tax_Helper_Data')->shippingPriceIncludesTax($quote->getStore())) { $includingTax = Mage::helper('Mage_Tax_Helper_Data')->getShippingPrice( $excludingTax, true, $qAddress, $quote->getCustomerTaxClassId() ); $shippingTax = $includingTax - $excludingTax; $qAddress->setShippingTaxAmount($this->_reCalculateToStoreCurrency($shippingTax, $quote)) ->setBaseShippingTaxAmount($shippingTax) ->setShippingInclTax($includingTax) ->setBaseShippingInclTax($this->_reCalculateToStoreCurrency($includingTax, $quote)); } else { if ($method == 'googlecheckout_carrier') { $qAddress->setShippingTaxAmount(0) ->setBaseShippingTaxAmount(0); } }*/ } else { $qAddress->setShippingMethod(null); } $qAddress->setGrandTotal($this->_reCalculateToStoreCurrency($this->getData('root/order-total/VALUE'), $quote)); $qAddress->setBaseGrandTotal($this->getData('root/order-total/VALUE')); }
public function validate(Varien_Object $object) { /*$customerId = $object->getQuote()->getCustomerId(); if ($customerId){ $customer = Mage::getModel('customer/customer')->load($customerId); $address = $customer->getPrimaryBillingAddress(); } else { return false; }*/ //Mage_Checkout_Model_Cart //if ($object instanceof Mage_Sales_Model_Order && $order->getId()) //print_r(Mage::helper('checkout/cart')->getCart()); $customerId = $object->getQuote()->getCustomerId(); if ($customerId) { $customer = Mage::getModel('customer/customer')->load($customerId); if ($address = $object->getPrimaryBillingAddress()) { return parent::validate($address); } } return false; /*if ($address = $object->getPrimaryBillingAddress()){ return parent::validate($address); } else { return false; }*/ }
/** * Build request for getting token * * @param Mage_Sales_Model_Order_Payment $payment * @return Varien_Object */ protected function _buildTokenRequest(Varien_Object $payment, $amount) { $orderId = null; $fullAmount = $payment->getAdditionalInformation('authorization_amount'); $salesDocument = $payment->getOrder(); if (!$salesDocument) { $salesDocument = $payment->getQuote(); if (!$salesDocument->getReservedOrderId()) { $salesDocument->reserveOrderId(); } $orderId = $salesDocument->getReservedOrderId(); } else { $orderId = $salesDocument->getIncrementId(); } $request = $this->_buildBasicRequest($payment); if (empty($salesDocument)) { return $request; } $request->setCreatesecuretoken('Y')->setSecuretokenid($this->_generateSecureTokenId())->setTrxtype($this->_getTrxTokenType())->setAmt($this->_formatStr('%.2F', $amount))->setCurrency($salesDocument->getBaseCurrencyCode())->setInvnum($orderId)->setCustref($orderId)->setPonum($salesDocument->getId()); if ($fullAmount != Mage_Paypal_Model_Config::AUTHORIZATION_AMOUNT_FULL) { $request->setSubtotal($this->_formatStr('%.2F', $salesDocument->getBaseSubtotal()))->setTaxamt($this->_formatStr('%.2F', $salesDocument->getBaseTaxAmount()))->setFreightamt($this->_formatStr('%.2F', $salesDocument->getBaseShippingAmount())); } $billing = $salesDocument->getBillingAddress(); if (!empty($billing)) { $request->setFirstname($billing->getFirstname())->setLastname($billing->getLastname())->setStreet(implode(' ', $billing->getStreet()))->setCity($billing->getCity())->setState($billing->getRegionCode())->setZip($billing->getPostcode())->setCountry($billing->getCountry())->setEmail($salesDocument->getCustomerEmail()); } $shipping = $salesDocument->getShippingAddress(); if (!empty($shipping)) { $this->_applyCountryWorkarounds($shipping); $request->setShiptofirstname($shipping->getFirstname())->setShiptolastname($shipping->getLastname())->setShiptostreet(implode(' ', $shipping->getStreet()))->setShiptocity($shipping->getCity())->setShiptostate($shipping->getRegionCode())->setShiptozip($shipping->getPostcode())->setShiptocountry($shipping->getCountry()); } //pass store Id to request $request->setUser1($salesDocument->getStoreId())->setUser2($this->_getSecureSilentPostHash($payment)); return $request; }
public function validate(Varien_Object $object) { $customerId = $object->getQuote()->getCustomerId(); if ($customerId) { $customer = Mage::getModel('customer/customer')->load($customerId); $datas = $customer->getData(); return parent::validate($datas); } return false; //if ($object instanceof Mage_Sales_Model_Order && $order->getId()) /* if ($datas = $object->getData()){ return parent::validate($object); } else { return false; }*/ }
/** * @param Varien_Object $object * @return bool */ public function validate(Varien_Object $object) { $address = $object; if (!$address instanceof Mage_Sales_Model_Quote_Address) { if ($object->getQuote()->isVirtual()) { $address = $object->getQuote()->getBillingAddress(); } else { $address = $object->getQuote()->getShippingAddress(); } } $address->setCustomerGroupCondition($this->getValue()); return parent::validate($address); }