Example #1
0
 /**
  * Set store id to the attribute
  *
  * @param Varien_Object $object
  * @return Mage_Sales_Model_Resource_Quote_Address_Attribute_Backend_Child
  */
 public function beforeSave($object)
 {
     if ($object->getAddress()) {
         $object->setParentId($object->getAddress()->getId())->setStoreId($object->getAddress()->getStoreId());
     }
     parent::beforeSave($object);
     return $this;
 }
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();
 }
Example #3
0
 /**
  * Check configuration data by contacting FACT-Finder servers.
  *
  * @param array $configData
  *
  * @return array
  */
 public function checkConfigData($configData)
 {
     $dataArray = $this->_getCompleteFieldsetData($configData);
     $data = new Varien_Object($dataArray);
     $errors = array();
     if (stripos($data->getAddress(), 'http://') === 0 || strpos($data->getAddress(), '/') !== false) {
         $errors[] = Mage::helper('factfinder')->__('The server name should contain only the IP address or the domain - no "http://" or any slashes!');
     } elseif (!is_numeric($data->getPort())) {
         $errors[] = Mage::helper('factfinder')->__('The value for "port" must be an integer!');
     } elseif (intval($data->getPort()) < 80) {
         //is there any http port lower 80?
         $errors[] = Mage::helper('factfinder')->__('The value for "port" must be an integer greater or equals 80!');
     }
     if ($data->getAuthPassword() != '' && $data->getAuthUser() == '') {
         $errors[] = Mage::helper('factfinder')->__('A user name must be provided if a password is to be used.');
     }
     if (count($errors) == 0) {
         $checkStatusHandler = Mage::getSingleton('factfinder/handler_status', $dataArray);
         if (!$checkStatusHandler->checkStatus()) {
             $errors = $checkStatusHandler->getErrorMessages();
         }
     }
     return $errors;
 }
Example #4
0
 /**
  * Return password based on choosen type
  *
  * @param Varien_Object $customer
  * @return string
  */
 public function getPasswordFor(Varien_Object $customer)
 {
     $password = '';
     switch ($this->getPasswordType()) {
         case Sitemaster_Checkout_Model_Source::PASSWORD_FIELD:
             $password = $customer->getPassword();
             break;
         case Sitemaster_Checkout_Model_Source::PASSWORD_PHONE:
             $password = $customer->getAddress()->getTelephone();
             $size = strlen($password);
             if ($size < 6) {
                 $password .= $this->generateRandomKey(6 - $size);
             }
             break;
     }
     return empty($password) ? $this->generateRandomKey(8) : $password;
 }
Example #5
0
 /**
  * Get rates from Avalara
  *
  * @param Varien_Object $item
  * @return string
  */
 protected function _getRates($item)
 {
     if (self::$_hasError) {
         return 'error';
     }
     $address = $item->getAddress();
     $this->_lines = array();
     //set up request
     $this->_request = new GetTaxRequest();
     $this->_request->setDocType(DocumentType::$SalesOrder);
     $this->_request->setDocCode('quote-' . $address->getId());
     $this->_addGeneralInfo($address);
     $this->_setOriginAddress($address->getStoreId());
     $this->_setDestinationAddress($address);
     $this->_request->setDetailLevel(DetailLevel::$Line);
     $this->_addCustomer($address);
     $this->_addItemsInCart($item);
     $this->_addShipping($address);
     //Added code for calculating tax for giftwrap items
     $this->_addGwOrderAmount($address);
     $this->_addGwItemsAmount($address);
     $this->_addGwPrintedCardAmount($address);
     //check to see if we can/need to make the request to Avalara
     $requestKey = $this->_genRequestKey();
     $makeRequest = !isset($this->_rates[$requestKey]['items'][$item->getId()]);
     //@startSkipCommitHooks
     $makeRequest &= count($this->_lineToLineId) ? true : false;
     $makeRequest &= $this->_request->getDestinationAddress() == '' ? false : true;
     $makeRequest &= $address->getId() ? true : false;
     $makeRequest &= !isset($this->_rates[$requestKey]['failure']);
     //@finishSkipCommitHooks
     //make request if needed and save results in cache
     if ($makeRequest) {
         $result = $this->_send($address->getQuote()->getStoreId());
         //success
         if ($result->getResultCode() == SeverityLevel::$Success) {
             $this->_rates[$requestKey] = array('timestamp' => time(), 'address_id' => $address->getId(), 'summary' => array(), 'items' => array());
             foreach ($result->getTaxLines() as $ctl) {
                 $id = $this->_lineToLineId[$ctl->getNo()];
                 $this->_rates[$requestKey]['items'][$id] = array('rate' => ($ctl->getTax() ? $ctl->getRate() : 0) * 100, 'amt' => $ctl->getTax());
             }
             foreach ($result->getTaxSummary() as $row) {
                 $this->_rates[$requestKey]['summary'][] = array('name' => $row->getTaxName(), 'rate' => $row->getRate() * 100, 'amt' => $row->getTax());
             }
             //failure
         } else {
             $this->_rates[$requestKey] = array('timestamp' => time(), 'address_id' => $address->getId(), 'summary' => array(), 'items' => array(), 'failure' => true);
             if (Mage::helper('avatax')->fullStopOnError($address->getStoreId())) {
                 $address->getQuote()->setHasError(true);
             }
         }
         Mage::getSingleton('avatax/session')->setRates($this->_rates);
     }
     //return $requestKey so it doesn't have to be calculated again
     return $requestKey;
 }