/** * Retrieve store configuration data * * @param string $path * @param string $scope * @return string|null */ public function getConfig($path) { $origPath = $path; $path = $this->preparePath($path); if (isset($this->_configCache[$path])) { return $this->_configCache[$path]; } $config = Mage::getConfig(); /* Check Vendor wise/group wise/default */ $fullPath = 'stores/' . $this->getCode() . '/' . $path; $data = $config->getNode($fullPath); if (!$data && !Mage::isInstalled()) { $data = $config->getNode('default/' . $path); } /* Check Group Wise */ if (!$data) { $path = $this->preparePath($origPath, null, 2); $fullPath = 'stores/' . $this->getCode() . '/' . $path; $data = $config->getNode($fullPath); if (!$data && !Mage::isInstalled()) { $data = $config->getNode('default/' . $path); } /* if(preg_match('/ced_/i',$path)) { $id = 0; if(Mage::registry('current_order_vendor')) $id = Mage::registry('current_order_vendor'); Mage::log($id.'=='.$path."--val: ".print_r($data, true),null,'cscommission_path.log'); } */ /* $path = $origPath; */ } /* Check Default Value*/ if (!$data) { $fullPath = 'stores/' . $this->getCode() . '/' . $origPath; $data = $config->getNode($fullPath); if (!$data && !Mage::isInstalled()) { $data = $config->getNode('default/' . $origPath); } $path = $origPath; } if (!$data) { return null; } if (strpos($path, 'ced_') !== false && !Mage::app()->getStore()->isAdmin()) { $result = new Varien_Object(); Mage::dispatchEvent('ced_csgroup_config_data_change_after', array('result' => $result, 'path' => $path, 'groupdata' => $this->_processConfigValue($fullPath, $path, $data))); if ($result->getResult()) { return $result->getResult(); } } return $this->_processConfigValue($fullPath, $path, $data); }
public function render(Varien_Object $row) { if ($row->getResult() === NULL || $row->getResult() == 0) { return '<span class="grid-severity-major"><span>' . Mage::helper('xtento_orderexport')->__('No Result') . '</span></span>'; } else { if ($row->getResult() == 1) { return '<span class="grid-severity-notice"><span>' . Mage::helper('xtento_orderexport')->__('Success') . '</span></span>'; } else { if ($row->getResult() == 2) { return '<span class="grid-severity-minor"><span>' . Mage::helper('xtento_orderexport')->__('Warning') . '</span></span>'; } else { if ($row->getResult() == 3) { return '<span class="grid-severity-critical"><span>' . Mage::helper('xtento_orderexport')->__('Failed') . '</span></span>'; } } } } return ''; }
/** * This method will dispatch the events 'magehost_clean_backend_cache_before' * and 'magehost_clean_backend_cache_after'. * Event listeners can change the mode or tags. * * {@inheritdoc} */ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) { $transportObject = new Varien_Object(); /** @noinspection PhpUndefinedMethodInspection */ $transportObject->setMode($mode); /** @noinspection PhpUndefinedMethodInspection */ $transportObject->setTags($tags); Mage::dispatchEvent('jv_clean_backend_cache', array('transport' => $transportObject)); // deprecated Mage::dispatchEvent('magehost_clean_backend_cache_before', array('transport' => $transportObject)); /** @noinspection PhpUndefinedMethodInspection */ $mode = $transportObject->getMode(); /** @noinspection PhpUndefinedMethodInspection */ $tags = $transportObject->getTags(); $result = parent::clean($mode, $tags); $transportObject->setResult($result); Mage::dispatchEvent('magehost_clean_backend_cache_after', array('transport' => $transportObject)); $result = $transportObject->getResult(); return $result; }
/** * configure attribute values */ public function configureAction() { $type = $this->getRequest()->getParam('type'); $attributeId = $this->getRequest()->getParam('attribute_id'); $values = urldecode($this->getRequest()->getParam('val')); $values = Mage::helper('core')->jsonDecode($values); switch ($type) { case 'color': $return = $this->_configureColor($attributeId, $values); break; case 'image': $return = $this->_configureImage($attributeId, $values); break; default: $result = array(); $resultObject = new Varien_Object(array('type' => $type, 'result' => $result, 'attribute_id' => $attributeId)); Mage::dispatchEvent('easylife_switcher_configure_transform', array('result' => $resultObject)); $return = $resultObject->getResult(); break; } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($return)); }
/** * If response is failed throw exception * Set token data in payment object * * @param Varien_Object $response * @param Mage_Sales_Model_Order_Payment $payment * @throws Mage_Core_Exception */ protected function _processTokenErrors($response, $payment) { if (!$response->getSecuretoken() && $response->getResult() != self::RESPONSE_CODE_APPROVED && $response->getResult() != self::RESPONSE_CODE_FRAUDSERVICE_FILTER) { Mage::throwException($response->getRespmsg()); } else { $payment->setAdditionalInformation('secure_token_id', $response->getSecuretokenid())->setAdditionalInformation('secure_token', $response->getSecuretoken()); } }
public function renderHtml($block, $part, $data = array()) { $result = new Varien_Object(); switch ($part) { case 'groups': $result->setResult($this->getNoGroups($block->getFilters())); break; case 'name_attributes': echo ' data-id="' . $this->getFilterLayoutName($block, $data['filter']->getFilterOptions()) . '"'; break; case 'group_attributes': echo ' data-id="' . $block->getShowInFilter() . '-' . $data['group']->getId() . '"'; break; case 'menu_visible': $result->setResult(false); break; case 'currently_shopping_by': $result->setResult(true); break; case 'name_action': case 'group_action': $result->setResult(array()); break; } Mage::dispatchEvent('m_advanced_filter_' . $part, array_merge($data, compact('block', 'result'))); return $result->getResult(); }
/** * Post request to gateway and return response * * @param Varien_Object $request * @return Varien_Object */ protected function _postRequest(Varien_Object $request) { $debugData = array('request' => $request->getData()); $client = new Varien_Http_Client(); $result = new Varien_Object(); $_config = array('maxredirects' => 5, 'timeout' => 30); $_isProxy = $this->getConfigData('use_proxy', false); if ($_isProxy) { $_config['proxy'] = $this->getConfigData('proxy_host') . ':' . $this->getConfigData('proxy_port'); //http://proxy.shr.secureserver.net:3128', $_config['httpproxytunnel'] = true; $_config['proxytype'] = CURLPROXY_HTTP; } $client->setUri($this->_getTransactionUrl())->setConfig($_config)->setMethod(Zend_Http_Client::POST)->setParameterPost($request->getData())->setHeaders('X-VPS-VIT-CLIENT-CERTIFICATION-ID: 33baf5893fc2123d8b191d2d011b7fdc')->setHeaders('X-VPS-Request-ID: ' . $request->getRequestId())->setHeaders('X-VPS-CLIENT-TIMEOUT: ' . $this->_clientTimeout); try { /** * we are sending request to payflow pro without url encoding * so we set up _urlEncodeBody flag to false */ $response = $client->setUrlEncodeBody(false)->request(); } catch (Exception $e) { $result->setResponseCode(-1)->setResponseReasonCode($e->getCode())->setResponseReasonText($e->getMessage()); $debugData['result'] = $result->getData(); $this->_debug($debugData); throw $e; } $response = strstr($response->getBody(), 'RESULT'); $valArray = explode('&', $response); foreach ($valArray as $val) { $valArray2 = explode('=', $val); $result->setData(strtolower($valArray2[0]), $valArray2[1]); } $result->setResultCode($result->getResult())->setRespmsg($result->getRespmsg()); $debugData['result'] = $result->getData(); $this->_debug($debugData); return $result; }
/** * If response is failed throw exception * Set token data in payment object * * @param Varien_Object $response * @param Mage_Sales_Model_Order_Payment $payment * @throws Mage_Core_Exception */ protected function _processTokenErrors($response, $payment) { if ($response->getResult() == self::RESPONSE_CODE_INVALID_AMOUNT) { throw new Mage_Paypal_Exception(Mage::helper('paypal')->__('Invalid Amount')); } elseif (!$response->getSecuretoken() && $response->getResult() != self::RESPONSE_CODE_APPROVED && $response->getResult() != self::RESPONSE_CODE_FRAUDSERVICE_FILTER) { Mage::throwException($response->getRespmsg()); } else { $payment->setAdditionalInformation('secure_token_id', $response->getSecuretokenid())->setAdditionalInformation('secure_token', $response->getSecuretoken()); } }
/** * This method will dispatch the events 'magehost_clean_backend_cache_before' * and 'magehost_clean_backend_cache_after'. * Event listeners can change the mode or tags. * This method will return false when clean failed. * * {@inheritdoc} */ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) { $result = false; $transportObject = new Varien_Object(); /** @noinspection PhpUndefinedMethodInspection */ $transportObject->setMode($mode); /** @noinspection PhpUndefinedMethodInspection */ $transportObject->setTags($tags); Mage::dispatchEvent('jv_clean_backend_cache', array('transport' => $transportObject)); // deprecated Mage::dispatchEvent('magehost_clean_backend_cache_before', array('transport' => $transportObject)); /** @noinspection PhpUndefinedMethodInspection */ $mode = $transportObject->getMode(); /** @noinspection PhpUndefinedMethodInspection */ $tags = $transportObject->getTags(); if ($this->works) { try { $result = parent::clean($mode, $tags); } catch (CredisException $e) { $this->processRedisException($e, 'remove'); $result = false; } catch (RedisException $e) { $this->processRedisException($e, 'remove'); $result = false; } catch (Zend_Cache_Exception $e) { $this->processRedisException($e, 'remove'); $result = false; } } $transportObject->setResult($result); Mage::dispatchEvent('magehost_clean_backend_cache_after', array('transport' => $transportObject)); $result = $transportObject->getResult(); return $result; }
/** * Collect and combine rates from vendor carriers * * @param Mage_Shipping_Model_Rate_Request $request * @return Mage_Shipping_Model_Rate_Result|boolean */ public function collectRates(Mage_Shipping_Model_Rate_Request $request) { if (!$this->getConfigFlag('active')) { return false; } $this->_rawRequest = $request; $hlp = Mage::helper('udropship'); $hlpd = Mage::helper('udropship/protected'); $carrierNames = Mage::getSingleton('udropship/source')->getCarriers(); // get available dropship shipping methods $shipping = $hlp->getShippingMethods(); foreach ($shipping as $s) { $s->setIsSkipped(false); } // prepare data $items = $request->getAllItems(); try { $hlpd->prepareQuoteItems($items); } catch (Exception $e) { return; } if (!$hlpd->getQuote()) { return; } $quote = $hlpd->getQuote(); $quoteWebsiteId = false; if ($quote->getStore() instanceof Varien_Object) { $quoteWebsiteId = $quote->getStore()->getWebsiteId(); } $address = $hlpd->getQuote()->getShippingAddress(); foreach ($items as $item) { if ($item->getAddress()) { $address = $item->getAddress(); } break; } Mage::dispatchEvent('udropship_carrier_collect_before', array('request' => $request, 'address' => $address)); $requests = $hlpd->getRequestsByVendor($items, $request); $evTransport = new Varien_Object(array('requests' => $requests, 'orig_request' => $request)); Mage::dispatchEvent('udropship_carrier_process_vendor_requests', array('transport' => $evTransport, 'address' => $address)); $requests = $evTransport->getRequests(); if ($quote->getUdropshipCarrierError()) { $error = Mage::getModel('shipping/rate_result_error'); $error->setCarrier($this->_code); $error->setCarrierTitle($this->getConfigData('title')); $errorMsg = $this->getConfigData('specificerrmsg'); $error->setErrorMessage($quote->getUdropshipCarrierError() ? $quote->getUdropshipCarrierError() : $errorMsg); return $error; } $requestVendors = array_keys($requests); // build separate requests grouped by carrier and vendor $carriers = array(); $numMethodsPerVendor = array(); $firstVendorRequests = array(); foreach ($requests as $vId => $vRequests) { foreach ($vRequests as $cCode => $r) { if (empty($firstVendorRequests[$vId])) { $firstVendorRequests[$vId] = $r; } #$cCode = $r->getCarrierCode(); $carriers[$cCode][$vId]['request'] = $r; $methods = $hlp->getVendor($vId)->getShippingMethods(); foreach ($methods as $__m) { foreach ($__m as $m) { if ($s = $shipping->getItemById($m['shipping_id'])) { $s->useProfile($hlp->getVendor($vId)); $carriers[$cCode][$vId]['methods'][$s->getShippingCode()] = $s->getSystemMethods($cCode); $s->resetProfile(); } } } } // skip methods that are not shared by ALL vendors $vendorMethods = $hlp->getVendor($vId)->getShippingMethods(); foreach ($shipping as $s) { if (empty($vendorMethods[$s->getId()])) { $s->setIsSkipped(true); } else { $_isSkippedShipping = new Varien_Object(array('result' => false)); Mage::dispatchEvent('udropship_vendor_shipping_check_skipped', array('shipping' => $s, 'address' => $address, 'vendor' => $hlp->getVendor($vId), 'request' => $firstVendorRequests[$vId], 'result' => $_isSkippedShipping)); $s->setIsSkipped($_isSkippedShipping->getResult()); } $sWebsites = $s->getWebsiteIds(); if (!is_array($sWebsites)) { $sWebsites = array($sWebsites); } $sWebsites = array_filter($sWebsites); if (!empty($sWebsites) && false !== $quoteWebsiteId && !in_array($quoteWebsiteId, $sWebsites)) { $s->setIsSkipped(true); } } } // quote.udropship_shipping_details $details = array('version' => $hlp->getVersion()); // vendors participating in the estimate $vendors = array(); $errorAction = $hlpd->getStore()->getConfig('udropship/customer/estimate_error_action'); // send actual requests and collect results foreach ($carriers as $cCode => $requests) { $keys = array_keys($requests); foreach ($keys as $k) { $vendor = $hlp->getVendor($k); $systemMethods = $hlp->getMultiSystemShippingMethodsByProfile($vendor); $vMethods = $vendor->getShippingMethods(); $result = $hlpd->collectVendorCarrierRates($requests[$k]['request']); if ($result === false) { if ($errorAction == 'fail') { //return $hlpd->errorResult(); continue; } elseif ($errorAction == 'skip') { continue; } } $rates = $result->getAllRates(); $keys1 = array_keys($rates); foreach ($keys1 as $k1) { if ($rates[$k1] instanceof Mage_Shipping_Model_Rate_Result_Error) { if ($errorAction == 'fail') { //return $hlpd->errorResult('udropship', $rates[$k1]->getErrorMessage()); continue 2; } elseif ($errorAction == 'skip') { continue 2; } } $wildcardUsed = false; if (empty($systemMethods[$rates[$k1]->getCarrier()][$rates[$k1]->getMethod()])) { if (!empty($systemMethods[$rates[$k1]->getCarrier()]['*'])) { $wildcardUsed = true; } else { continue; } } if ($wildcardUsed) { $smArray = $systemMethods[$rates[$k1]->getCarrier()]['*']; } else { $smArray = $systemMethods[$rates[$k1]->getCarrier()][$rates[$k1]->getMethod()]; } foreach ($smArray as $s) { $s->useProfile($vendor); if ($s->getIsSkipped() || !isset($vMethods[$s->getId()])) { continue; } foreach ($vMethods[$s->getId()] as $vMethod) { $vendorCode = $vendor->getCarrierCode(); if ($requests[$k]['request']->getForcedCarrierFlag()) { $ecCode = $ocCode = $rates[$k1]->getCarrier(); } else { $ecCode = !empty($vMethod['est_carrier_code']) ? $vMethod['est_carrier_code'] : (!empty($vMethod['carrier_code']) ? $vMethod['carrier_code'] : $vendorCode); $ocCode = !empty($vMethod['carrier_code']) ? $vMethod['carrier_code'] : $vendorCode; } $oldEstCode = null; if (!empty($details['methods'][$s->getShippingCode()]['vendors'][$k]['est_code'])) { list($oldEstCode, ) = explode('_', $details['methods'][$s->getShippingCode()]['vendors'][$k]['est_code'], 2); } if ($ecCode != $rates[$k1]->getCarrier()) { if ($vendor->getUseRatesFallback() && !Mage::helper('udropship')->isUdsprofileActive()) { if ($oldEstCode == $ecCode) { continue; } elseif ($oldEstCode != $ecCode && $ecCode == $rates[$k1]->getCarrier()) { } elseif ($oldEstCode != $ocCode && $ocCode == $rates[$k1]->getCarrier()) { $ecCode = $ocCode; } elseif (!$oldEstCode && $vendorCode == $rates[$k1]->getCarrier()) { $ecCode = $vendorCode; } else { continue; } } else { continue; } } if ('**estimate**' == $ocCode) { $ocCode = $ecCode; } if ($wildcardUsed && $ecCode != $ocCode) { continue; } if (Mage::helper('udropship')->isUdsprofileActive()) { $codeToCompare = $vMethod['carrier_code'] . '_' . $vMethod['method_code']; if (!empty($vMethod['est_use_custom'])) { $codeToCompare = $vMethod['est_carrier_code'] . '_' . $vMethod['est_method_code']; } if ($codeToCompare != $rates[$k1]->getCarrier() . '_' . $rates[$k1]->getMethod()) { continue; } } $rates[$k1]->setUdsIsSkip(false); Mage::dispatchEvent('udropship_process_vendor_carrier_single_rate_result', array('vendor_method' => $vMethod, 'udmethod' => $s, 'address' => $address, 'vendor' => $vendor, 'request' => $requests[$k]['request'], 'rate' => $rates[$k1])); if ($rates[$k1]->getUdsIsSkip()) { continue; } $shipPrice = $this->getUdRatePrice($rates[$k1], $requests[$k]['request'], $s); $detail = array('cost' => sprintf('%.4f', $rates[$k1]->getCost()), 'price' => sprintf('%.4f', $shipPrice), 'price_excl' => sprintf('%.4f', $this->getShippingPrice($shipPrice, $vendor, $address, 'base')), 'price_incl' => sprintf('%.4f', $this->getShippingPrice($shipPrice, $vendor, $address, 'incl')), 'tax' => sprintf('%.4f', $this->getShippingPrice($shipPrice, $vendor, $address, 'tax')), 'est_code' => $rates[$k1]->getCarrier() . '_' . $rates[$k1]->getMethod(), 'est_carrier_title' => $rates[$k1]->getCarrierTitle(), 'est_method_title' => $rates[$k1]->getMethodTitle(), 'package_weight' => $requests[$k]['request']->getPackageWeight(), 'package_value' => $requests[$k]['request']->getPackageValue(), 'days_in_transit' => $s->getDaysInTransit()); if (Mage::helper('udropship')->isUdsprofileActive()) { $detail['sort_order'] = $vMethod['sort_order']; } $detail['is_free_shipping'] = (int) $this->isFwFreeShipping($rates[$k1], $requests[$k]['request'], $s); if ($ecCode == $ocCode) { $detail['code'] = $detail['est_code']; $detail['carrier_title'] = $detail['est_carrier_title']; $detail['method_title'] = $detail['est_method_title']; } else { $ocMethod = $s->getSystemMethods($ocCode); if (Mage::helper('udropship')->isUdsprofileActive()) { $ocMethod = $vMethod['method_code']; } if (empty($ocMethod)) { continue; } $methodNames = $hlp->getCarrierMethods($ocCode); $detail['code'] = $ocCode . '_' . $ocMethod; $detail['carrier_title'] = $carrierNames[$ocCode]; $detail['method_title'] = $methodNames[$ocMethod]; } $vendors[$k] = 1; $scKey = !$wildcardUsed ? $s->getShippingCode() : $s->getShippingCode() . '___' . $detail['code']; $details['methods'][$scKey]['id'] = $s->getShippingId(); if (Mage::helper('udropship')->isUdsprofileActive() && !empty($details['methods'][$scKey]['vendors'][$k]) && $details['methods'][$scKey]['vendors'][$k]['sort_order'] < $detail['sort_order']) { continue; } if (($curUdpoSeqNumber = $requests[$k]['request']->getUdpoSeqNumber()) && !empty($details['methods'][$scKey]['vendors'][$k])) { $snByVendor = $address->getSeqNumbersByVendor(); $snByVendor[$k][$curUdpoSeqNumber][$scKey] = true; $address->setSeqNumbersByVendor($snByVendor); $ratesBySeqNumber = @$details['methods'][$scKey]['vendors'][$k]['rates_by_seq_number']; if (!is_array($ratesBySeqNumber)) { $ratesBySeqNumber = array(); } if ($oldRateBySeqNumber = @$ratesBySeqNumber[$curUdpoSeqNumber]) { $details['methods'][$scKey]['vendors'][$k]['cost'] -= $oldRateBySeqNumber['cost']; $details['methods'][$scKey]['vendors'][$k]['price'] -= $oldRateBySeqNumber['price']; $details['methods'][$scKey]['vendors'][$k]['price_excl'] -= $oldRateBySeqNumber['price_excl']; $details['methods'][$scKey]['vendors'][$k]['price_incl'] -= $oldRateBySeqNumber['price_incl']; $details['methods'][$scKey]['vendors'][$k]['tax'] -= $oldRateBySeqNumber['tax']; } $ratesBySeqNumber[$curUdpoSeqNumber] = $detail; //if (is_array($snByVendor) && $curUdpoSeqNumber>=max(array_keys($snByVendor))) { $_resCost = $detail['cost'] + $details['methods'][$scKey]['vendors'][$k]['cost']; $_resPrice = $detail['price'] + $details['methods'][$scKey]['vendors'][$k]['price']; $_resPriceExcl = $detail['price_excl'] + $details['methods'][$scKey]['vendors'][$k]['price_excl']; $_resPriceIncl = $detail['price_incl'] + $details['methods'][$scKey]['vendors'][$k]['price_incl']; $_resTax = $detail['tax'] + $details['methods'][$scKey]['vendors'][$k]['tax']; $details['methods'][$scKey]['vendors'][$k] = $detail; $details['methods'][$scKey]['vendors'][$k]['cost'] = $_resCost; $details['methods'][$scKey]['vendors'][$k]['price'] = $_resPrice; $details['methods'][$scKey]['vendors'][$k]['price_excl'] = $_resPriceExcl; $details['methods'][$scKey]['vendors'][$k]['price_incl'] = $_resPriceIncl; $details['methods'][$scKey]['vendors'][$k]['tax'] = $_resTax; //} $details['methods'][$scKey]['vendors'][$k]['is_free_shipping'] = $detail['is_free_shipping']; $details['methods'][$scKey]['vendors'][$k]['rates_by_seq_number'] = $ratesBySeqNumber; } else { $details['methods'][$scKey]['vendors'][$k] = $detail; if (!empty($curUdpoSeqNumber)) { $snByVendor = $address->getSeqNumbersByVendor(); $snByVendor[$k][$curUdpoSeqNumber][$scKey] = true; $address->setSeqNumbersByVendor($snByVendor); $details['methods'][$scKey]['vendors'][$k]['rates_by_seq_number'] = array($curUdpoSeqNumber => $detail); } } if ($wildcardUsed) { $details['methods'][$scKey]['wildcard_code'] = $detail['code']; $details['methods'][$scKey]['wildcard_carrier_title'] = $detail['carrier_title']; $details['methods'][$scKey]['wildcard_method_title'] = $detail['method_title']; } } } foreach ($smArray as $s) { $s->resetProfile(); } } } } $snByVendor = $address->getSeqNumbersByVendor(); if (!empty($snByVendor) && is_array($snByVendor)) { $totalSnUsed = array(); $methodsUsedBySn = array(); foreach ($snByVendor as $vId => $snData) { foreach ($snData as $__sn => $snMethods) { $totalSnUsed[$vId . '-' . $__sn] = 1; foreach ($snMethods as $_snMethod => $_dummy) { $methodsUsedBySn[$_snMethod][$vId . '-' . $__sn] = 1; } } } $totalSnUsed = array_sum($totalSnUsed); foreach ($methodsUsedBySn as $_snMethod => $_snMethodTotals) { if (array_sum($_snMethodTotals) < $totalSnUsed) { unset($details['methods'][$_snMethod]); } } } $address->setUdropshipShippingDetails(Zend_Json::encode($details)); #Mage::log($hlpd->getQuote()->getUdropshipShippingDetails()); #exit; // googlecheckout merchant calculations don't save address if (Mage::app()->getRequest()->getRouteName() == 'googlecheckout') { $transaction = Mage::getModel('core/resource_transaction'); $transaction->addObject($address); foreach ($request->getAllItems() as $item) { $transaction->addObject($item); } $transaction->save(); } if (empty($vendors) || $errorAction == 'fail' && count($vendors) < count($requestVendors)) { return $hlpd->errorResult('udropship'); } $totalMethod = Mage::getStoreConfig('udropship/customer/estimate_total_method'); // collect prices from details $totals = array(); $numVendors = sizeof($vendors); $processedMethods = array(); foreach ($details['methods'] as $mCode => $method) { $sId = $method['id']; unset($method['id']); if (in_array($method, $processedMethods)) { continue; } $processedMethods[] = $method; $method['id'] = $sId; $s = $shipping->getItemById($method['id']); // skip not common methods if ($s->getIsSkipped() || sizeof($method['vendors']) < $numVendors) { continue; } if (empty($totals[$mCode])) { $totals[$mCode] = array('is_free_shipping' => 1, 'cost' => 0, 'price' => 0, 'price_excl' => 0, 'price_incl' => 0, 'tax' => 0, 'title' => $s->getStoreTitle($quote->getStoreId())); if (!empty($method['wildcard_code'])) { $totals[$mCode]['title'] .= sprintf(' [%s - %s]', $method['wildcard_carrier_title'], $method['wildcard_method_title']); } } foreach ($method['vendors'] as $vId => $rate) { $totals[$mCode]['is_free_shipping'] = @$totals[$mCode]['is_free_shipping'] && @$rate['is_free_shipping']; $totals[$mCode]['cost'] = $hlp->applyEstimateTotalCostMethod($totals[$mCode]['cost'], $rate['cost']); $totals[$mCode]['price'] = $hlp->applyEstimateTotalPriceMethod($totals[$mCode]['price'], $rate['price']); $totals[$mCode]['price_excl'] = $hlp->applyEstimateTotalPriceMethod($totals[$mCode]['price_excl'], $rate['price_excl']); $totals[$mCode]['price_incl'] = $hlp->applyEstimateTotalPriceMethod($totals[$mCode]['price_incl'], $rate['price_incl']); $totals[$mCode]['tax'] = $hlp->applyEstimateTotalPriceMethod($totals[$mCode]['tax'], $rate['tax']); } } #Mage::log($totals); // return Magento formated shipping carrier result $result = Mage::getModel('shipping/rate_result'); // flat rate customization /* $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier('udropship'); $method->setCarrierTitle($dropshipCarrier->getConfigData('title')); $method->setMethod('flatrate'); $method->setMethodTitle('Flat Rate'); $method->setCost(7.5); $method->setPrice(7.5); $result->append($method); */ if (!empty($totals)) { foreach ($totals as $mCode => $total) { $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier('udropship'); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod($mCode); $method->setMethodTitle($total['title']); $method->setCost($total['cost']); if (!empty($total['is_free_shipping'])) { $method->setPrice(0); } else { $method->setPrice($this->getMethodPrice($total['price'], $mCode)); } $result->append($method); } } else { $error = Mage::getModel('shipping/rate_result_error'); $error->setCarrier($this->_code); $error->setCarrierTitle($this->getConfigData('title')); $errorMsg = $this->getConfigData('specificerrmsg'); $error->setErrorMessage($errorMsg); return $error; } Mage::dispatchEvent('udropship_carrier_collect_after', array('request' => $request, 'result' => $result, 'address' => $address, 'details' => $details)); return $result; }
/** * Adds rental start and end dates to custom options * * @param Varien_Object $buyRequest * @param null $product * @param null $processMode * @param string $productType * @return string * todo refactor /investigate more to additional_options(how the translations of options would work, might need a lot of effort) * this function should check if we are in global dates mode, should get the existing param etc, no need to modify query string on listing. * This will allow so adding a product from a different block from listing to work too */ public function prepareForCartAdvanced(Varien_Object $buyRequest, $product = null, $processMode = null, $productType = 'simple') { if (ITwebexperts_Payperrentals_Helper_Data::isBuyout($buyRequest)) { $product->addCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::BUYOUT_PRICE_OPTION, true, $product); return 'call_parent'; } if (!ITwebexperts_Payperrentals_Helper_Sso::isAllowedRenting()) { return Mage::helper('payperrentals')->__('You are not allowed renting. Please login on CNH'); } if ($productType != 'simple' && !ITwebexperts_Payperrentals_Helper_Data::isReservationAndRental($product)) { return 'call_parent'; } if ($buyRequest->getIsReservation() == ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_RENTAL) { return Mage::helper('payperrentals/membership')->addProductToQueue($product, $buyRequest, $productType == 'grouped' ? true : false); } $msg = $this->_completeBuyRequestObject($buyRequest, $product, $productType); if ($msg) { return $msg; } $resultObject = new Varien_Object(); Mage::dispatchEvent('prepare_advanced_before', array('buy_request' => $buyRequest, 'product_type' => $productType, 'product' => $product, 'result' => $resultObject)); if ($resultObject->getResult() != '') { return $resultObject->getResult(); } $this->_addCustomOptions($product, $buyRequest); ITwebexperts_Payperrentals_Helper_Date::saveDatesForGlobalUse((array) $buyRequest); return 'call_parent'; }
public function collectRates(Mage_Shipping_Model_Rate_Request $request) { #return Mage::helper('udsplit/protected')->collectRates($this, $request); if (!$this->getConfigFlag('active')) { return false; } $hl = Mage::helper('udropship'); $hlp = Mage::helper('udropship/protected'); $carrierNames = Mage::getSingleton('udropship/source')->getCarriers(); // prepare data $items = $request->getAllItems(); if (empty($items)) { return; } try { $hlp->prepareQuoteItems($items); } catch (Exception $e) { Mage::helper('udropship')->addMessageOnce($e->getMessage()); return; } foreach ($items as $item) { $quote = $item->getQuote(); break; } $address = $quote->getShippingAddress(); foreach ($items as $item) { if ($item->getAddress()) { $address = $item->getAddress(); } break; } Mage::dispatchEvent('udsplit_carrier_collect_before', array('request' => $request, 'address' => $address)); $requests = $hlp->getRequestsByVendor($items, $request); $evTransport = new Varien_Object(array('requests' => $requests)); Mage::dispatchEvent('udsplit_carrier_process_vendor_requests', array('transport' => $evTransport, 'address' => $address)); $requests = $evTransport->getRequests(); #foreach ($requests as $r) var_dump($r); exit; // get available dropship shipping methods $shipping = $hl->getShippingMethods(); $freeMethods = explode(',', Mage::getStoreConfig('carriers/udropship/free_method', $hlp->getStore())); if ($freeMethods) { $_freeMethods = array(); foreach ($freeMethods as $freeMethod) { if (is_numeric($freeMethod)) { if ($shipping->getItemById($freeMethod)) { $_freeMethods[] = $freeMethod; } } else { if ($shipping->getItemByColumnValue('shipping_code', $freeMethod)) { $_freeMethods[] = $freeMethod; } } $_freeMethods[] = $freeMethod; } $freeMethods = $_freeMethods; } $result = Mage::getModel('udropship/rateResult'); foreach ($requests as $vId => $vRequests) { $vendor = $hl->getVendor($vId); $systemMethods = $hl->getMultiSystemShippingMethodsByProfile($vendor); $vMethods = $vendor->getShippingMethods(); foreach ($vRequests as $cCode => $req) { $vResult = $hlp->collectVendorCarrierRates($req); $vRates = $vResult->getAllRates(); foreach ($vRates as $rate) { $wildcardUsed = false; $hasVendorMethod = false; $smArray = @$systemMethods[$rate->getCarrier()][$rate->getMethod()]; if (!empty($smArray)) { foreach ($smArray as $udMethod) { $hasVendorMethod = $hasVendorMethod || !empty($vMethods[$udMethod->getShippingId()]); } } if (!$hasVendorMethod) { if (!empty($systemMethods[$rate->getCarrier()]['*'])) { $wildcardUsed = true; } else { continue; } } if ($wildcardUsed) { $smArray = $systemMethods[$rate->getCarrier()]['*']; } foreach ($smArray as $udMethod) { $udMethod->useProfile($vendor); if (empty($vMethods[$udMethod->getShippingId()])) { continue; } foreach ($vMethods[$udMethod->getId()] as $vMethod) { $_isSkippedShipping = new Varien_Object(array('result' => false)); Mage::dispatchEvent('udropship_vendor_shipping_check_skipped', array('shipping' => $udMethod, 'address' => $address, 'vendor' => $vendor, 'request' => $req, 'result' => $_isSkippedShipping)); if ($_isSkippedShipping->getResult()) { continue; } if ($freeMethods && Mage::getStoreConfigFlag('carriers/udropship/free_shipping_allowed', $request->getStoreId()) && Mage::getStoreConfigFlag('carriers/udropship/freeweight_allowed', $request->getStoreId()) && $this->isRuleFreeshipping($req) && in_array($udMethod->getShippingCode(), $freeMethods)) { $rate->setPrice(0); $rate->setIsFwFreeShipping(true); } $rate->setPrice($this->getMyMethodPrice($rate->getPrice(), $req, $udMethod->getShippingCode())); $rate->setUdsIsSkip(false); Mage::dispatchEvent('udropship_process_vendor_carrier_single_rate_result', array('vendor_method' => $vMethod, 'udmethod' => $udMethod, 'address' => $address, 'vendor' => $vendor, 'request' => $req, 'rate' => $rate)); if ($rate->getUdsIsSkip()) { continue; } $vendorCode = $vendor->getCarrierCode(); if ($req->getForcedCarrierFlag()) { $ecCode = $ocCode = $rate->getCarrier(); } else { $ecCode = !empty($vMethod['est_carrier_code']) ? $vMethod['est_carrier_code'] : (!empty($vMethod['carrier_code']) ? $vMethod['carrier_code'] : $vendorCode); $ocCode = !empty($vMethod['carrier_code']) ? $vMethod['carrier_code'] : $vendorCode; } $oldEstCode = null; $resultKey = sprintf('%s-%s', $vId, $udMethod->getShippingCode()); if (!empty($resultRates[$resultKey])) { $oldEstCode = $resultRates[$resultKey]->getUdEstCarrier(); if (Mage::helper('udropship')->isUdsprofileActive() && $resultRates[$resultKey]->getUdsprofileSortOrder() < $vMethod['sort_order']) { continue; } } if ($ecCode != $rate->getCarrier()) { if (!$wildcardUsed && $vendor->getUseRatesFallback() && !Mage::helper('udropship')->isUdsprofileActive()) { if ($oldEstCode == $ecCode) { continue; } elseif ($oldEstCode != $ocCode && $ocCode == $rate->getCarrier()) { $ecCode = $ocCode; } elseif (!$oldEstCode && $vendorCode == $rate->getCarrier()) { $ecCode = $vendorCode; } else { continue; } } else { continue; } } if ('**estimate**' == $ocCode) { $ocCode = $ecCode; } if ($wildcardUsed && $ecCode != $ocCode) { continue; } if ($ecCode != $rate->getCarrier()) { continue; } if (Mage::helper('udropship')->isUdsprofileActive()) { $codeToCompare = $vMethod['carrier_code'] . '_' . $vMethod['method_code']; if (!empty($vMethod['est_use_custom'])) { $codeToCompare = $vMethod['est_carrier_code'] . '_' . $vMethod['est_method_code']; } if ($codeToCompare != $rate->getCarrier() . '_' . $rate->getMethod()) { continue; } } if ($ocCode != $ecCode) { $ocMethod = $udMethod->getSystemMethods($ocCode); if (Mage::helper('udropship')->isUdsprofileActive()) { $ocMethod = $vMethod['method_code']; } if (empty($ocMethod)) { continue; } $methodNames = $hl->getCarrierMethods($ocCode); $rate->setCarrier($ocCode)->setMethod($ocMethod)->setCarrierTitle($carrierNames[$ocCode])->setMethodTitle($methodNames[$ocMethod]); } $rate->setPriority(@$vMethod['priority'])->setUdEstCarrier($ecCode)->setUdVendorMethod($vMethod)->setUdVid($vId)->setUdropshipShippingId($udMethod->getShippingId()); if (Mage::helper('udropship')->isUdsprofileActive()) { $rate->setUdsprofileSortOrder($vMethod['sort_order']); } if ($wildcardUsed) { $resultKey .= $rate->getCarrier() . '_' . $rate->getMethod(); } $resultRates[$resultKey] = $rate; break; } } foreach ($smArray as $udMethod) { $udMethod->resetProfile(); } } } } if (!empty($resultRates)) { foreach ($resultRates as $resultRate) { $result->append($resultRate); if ($exRate = $hl->getExtraChargeRate($req, $resultRate, $resultRate->getUdVid(), $resultRate->getUdVendorMethod())) { $result->append($exRate); } } } foreach ($items as $item) { $quote = $item->getQuote(); break; } if (empty($quote)) { $result->append($hlp->errorResult('udsplit')); return $result; } $address = $quote->getShippingAddress(); foreach ($items as $item) { if ($item->getAddress()) { $address = $item->getAddress(); } break; } $cost = 0; $price = 0; $details = $address->getUdropshipShippingDetails(); $methodCodes = array(); if ($details && ($details = Zend_Json::decode($details)) && !empty($details['methods'])) { foreach ($details['methods'] as $vId => $rate) { if (!empty($rate['code'])) { $methodCodes[$vId] = $rate['code']; } } } $totalMethod = Mage::getStoreConfig('udropship/customer/estimate_total_method'); $details = array('version' => Mage::helper('udropship')->getVersion()); $result->sortRatesByPriority(); $rates = $result->getAllRates(); $hasDefPatternMatch = array(); foreach ($rates as $rate) { if ($rate->getErrorMessage()) { continue; } $vId = $rate->getUdropshipVendor(); $vendor = $hl->getVendor($vId); if (!$vId) { continue; } $pattern = $vendor->getDefaultShippingMethodPattern(); if (!isset($hasDefPatternMatch[$vId])) { $hasDefPatternMatch[$vId] = false; } $hasDefPatternMatch[$vId] = $hasDefPatternMatch[$vId] || ($pattern ? preg_match('#' . preg_quote($pattern) . '#i', $rate->getMethodTitle()) : true); } $matchRank = array(); $costsByVid = $pricesByVid = array(); foreach ($rates as $rate) { if ($rate->getErrorMessage()) { continue; } $vId = $rate->getUdropshipVendor(); $vendor = $hl->getVendor($vId); if (!$vId) { continue; } $code = $rate->getCarrier() . '_' . $rate->getMethod(); $data = array('code' => $code, 'cost' => (double) $rate->getCost(), 'price' => (double) $rate->getPrice(), 'price_excl' => (double) $this->getShippingPrice($rate->getPrice(), $vendor, $address, 'base'), 'price_incl' => (double) $this->getShippingPrice($rate->getPrice(), $vendor, $address, 'incl'), 'tax' => (double) $this->getShippingPrice($rate->getPrice(), $vendor, $address, 'tax'), 'carrier_title' => $rate->getCarrierTitle(), 'method_title' => $rate->getMethodTitle(), 'is_free_shipping' => (int) $rate->getIsFwFreeShipping()); if (!isset($matchRank[$vId])) { $matchRank[$vId] = 0; } $pattern = $vendor->getDefaultShippingMethodPattern(); $defPatternMatch = $pattern ? preg_match('#' . preg_quote($pattern) . '#i', $rate->getMethodTitle()) : true; $isCurMatch = false; $curMatchRank = 0; if (!empty($methodCodes[$vId]) && $code == $methodCodes[$vId]) { $curMatchRank = 1000; $isCurMatch = true; } elseif ($vendor->getDefaultShippingId() && $vendor->getDefaultShippingId() == $rate->getUdropshipShippingId() && (!$rate->getHasExtraCharge() || (bool) $vendor->getIsExtraChargeShippingDefault() == (bool) $rate->getIsExtraCharge())) { $curMatchRank = 100; $isCurMatch = true; } elseif ($defPatternMatch) { $curMatchRank = 10; $isCurMatch = true; } elseif (empty($details['methods'][$vId])) { $curMatchRank = 1; $isCurMatch = true; } if ($isCurMatch && $curMatchRank > $matchRank[$vId]) { $matchRank[$vId] = $curMatchRank; // updating already chosen vendor shipping method price $details['methods'][$vId] = $data; $costsByVid[$vId] = $data['cost']; $pricesByVid[$vId] = $data['price']; } } $price = $cost = 0; foreach ($pricesByVid as $_vId => $_price) { $price = $hl->applyEstimateTotalPriceMethod($price, $pricesByVid[$_vId]); $cost = $hl->applyEstimateTotalCostMethod($cost, $costsByVid[$_vId]); } if ($rates) { $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier('udsplit'); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod('total'); $method->setMethodTitle('Total'); $method->setCost($price); //$method->setPrice($this->getMethodPrice($price, 'total')); $method->setPrice($price); $result->append($method); } else { $result->append($hlp->errorResult('udsplit')); } $address->setUdropshipShippingDetails(Zend_Json::encode($details)); $address->setShippingMethod('udsplit_total'); $address->setShippingDescription($this->getConfigData('title')); $address->setShippingAmount($price); Mage::dispatchEvent('udsplit_carrier_collect_after', array('request' => $request, 'result' => $result, 'address' => $address, 'details' => $details)); Mage::dispatchEvent('udropship_carrier_collect_after', array('request' => $request, 'result' => $result, 'address' => $address, 'details' => $details)); return $result; }