/** * Update product configuration for a cart item * * @return void */ public function execute() { $id = (int) $this->getRequest()->getParam('id'); $params = $this->getRequest()->getParams(); if (!isset($params['options'])) { $params['options'] = array(); } try { if (isset($params['qty'])) { $filter = new \Zend_Filter_LocalizedToNormalized(array('locale' => $this->_objectManager->get('Magento\\Framework\\Locale\\ResolverInterface')->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $quoteItem = $this->cart->getQuote()->getItemById($id); if (!$quoteItem) { throw new \Magento\Framework\Model\Exception(__("We can't find the quote item.")); } $item = $this->cart->updateItem($id, new \Magento\Framework\Object($params)); if (is_string($item)) { throw new \Magento\Framework\Model\Exception($item); } if ($item->getHasError()) { throw new \Magento\Framework\Model\Exception($item->getMessage()); } $related = $this->getRequest()->getParam('related_product'); if (!empty($related)) { $this->cart->addProductsByIds(explode(',', $related)); } $this->cart->save(); $this->_checkoutSession->setCartWasUpdated(true); $this->_eventManager->dispatch('checkout_cart_update_item_complete', array('item' => $item, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$this->_checkoutSession->getNoCartRedirect(true)) { if (!$this->cart->getQuote()->getHasError()) { $message = __('%1 was updated in your shopping cart.', $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($item->getProduct()->getName())); $this->messageManager->addSuccess($message); } $this->_goBack(); } } catch (\Magento\Framework\Model\Exception $e) { if ($this->_checkoutSession->getUseNotice(true)) { $this->messageManager->addNotice($e->getMessage()); } else { $messages = array_unique(explode("\n", $e->getMessage())); foreach ($messages as $message) { $this->messageManager->addError($message); } } $url = $this->_checkoutSession->getRedirectUrl(true); if ($url) { $this->getResponse()->setRedirect($url); } else { $cartUrl = $this->_objectManager->get('Magento\\Checkout\\Helper\\Cart')->getCartUrl(); $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($cartUrl)); } } catch (\Exception $e) { $this->messageManager->addException($e, __('We cannot update the item.')); $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e); $this->_goBack(); } $this->_redirect('*/*'); }
/** * Update customer's shopping cart * * @return void */ protected function _updateShoppingCart() { try { $cartData = $this->getRequest()->getParam('cart'); if (is_array($cartData)) { $filter = new \Zend_Filter_LocalizedToNormalized(array('locale' => $this->_objectManager->get('Magento\\Framework\\Locale\\ResolverInterface')->getLocaleCode())); foreach ($cartData as $index => $data) { if (isset($data['qty'])) { $cartData[$index]['qty'] = $filter->filter(trim($data['qty'])); } } if (!$this->cart->getCustomerSession()->getCustomerId() && $this->cart->getQuote()->getCustomerId()) { $this->cart->getQuote()->setCustomerId(null); } $cartData = $this->cart->suggestItemsQty($cartData); $this->cart->updateItems($cartData)->save(); } $this->_checkoutSession->setCartWasUpdated(true); } catch (\Magento\Framework\Model\Exception $e) { $this->messageManager->addError($this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($e->getMessage())); } catch (\Exception $e) { $this->messageManager->addException($e, __('We cannot update the shopping cart.')); $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e); } }
/** * Update product configuration for a cart item */ public function updateItemOptionsAction() { $cart = $this->_getCart(); $id = (int) $this->getRequest()->getParam('id'); $params = $this->getRequest()->getParams(); if (!isset($params['options'])) { $params['options'] = array(); } try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $quoteItem = $cart->getQuote()->getItemById($id); if (!$quoteItem) { Mage::throwException($this->__('Quote item is not found.')); } $item = $cart->updateItem($id, new Varien_Object($params)); if (is_string($item)) { Mage::throwException($item); } if ($item->getHasError()) { Mage::throwException($item->getMessage()); } $related = $this->getRequest()->getParam('related_product'); if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } $cart->save(); $this->_getSession()->setCartWasUpdated(true); $this->getLayout()->getUpdate()->addHandle('ajaxcart'); $this->loadLayout(); Mage::dispatchEvent('checkout_cart_update_item_complete', array('item' => $item, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$this->_getSession()->getNoCartRedirect(true)) { if (!$cart->getQuote()->getHasError()) { $message = $this->__('%s was updated in your shopping cart.', Mage::helper('core')->htmlEscape($item->getProduct()->getName())); $this->_getSession()->addSuccess($message); } $this->_goBack(); } } catch (Mage_Core_Exception $e) { $_response = Mage::getModel('ajaxcart/response'); $_response->setError(true); $messages = array_unique(explode("\n", $e->getMessage())); $json_messages = array(); foreach ($messages as $message) { $json_messages[] = Mage::helper('core')->escapeHtml($message); } $_response->setMessages($json_messages); $url = $this->_getSession()->getRedirectUrl(true); $_response->send(); } catch (Exception $e) { $this->_getSession()->addException($e, $this->__('Cannot update the item.')); Mage::logException($e); $_response = Mage::getModel('ajaxcart/response'); $_response->setError(true); $_response->setMessage($this->__('Cannot update the item.')); $_response->send(); } }
protected function _updateShoppingCart() { try { $cartData = $this->getRequest()->getParam('cart'); if (is_array($cartData)) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); foreach ($cartData as $index => $data) { if (isset($data['qty'])) { $cartData[$index]['qty'] = $filter->filter(trim($data['qty'])); } } $cart = $this->_getCart(); if (!$cart->getCustomerSession()->getCustomer()->getId() && $cart->getQuote()->getCustomerId()) { $cart->getQuote()->setCustomerId(null); } $cartData = $cart->suggestItemsQty($cartData); $cart->updateItems($cartData)->save(); } $this->_getSession()->setCartWasUpdated(true); } catch (Mage_Core_Exception $e) { $this->_getSession()->addError(Mage::helper('core')->escapeHtml($e->getMessage())); } catch (Exception $e) { $this->_getSession()->addException($e, $this->__('Cannot update shopping cart.')); Mage::logException($e); } }
/** * Returns the result of filtering $value * * @param string $value * @return string */ public function outputFilter($value) { $filterInput = new \Zend_Filter_LocalizedToNormalized(array('date_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, 'locale' => $this->_locale)); $filterInternal = new \Zend_Filter_NormalizedToLocalized(array('date_format' => $this->_dateFormat, 'locale' => $this->_locale)); $value = $filterInput->filter($value); $value = $filterInternal->filter($value); return $value; }
public function _set($fieldName, $value, $load = true) { if (strstr($fieldName, 'week_')) { $zendFilter = new Zend_Filter_LocalizedToNormalized(); $value = $zendFilter->filter($value); } parent::_set($fieldName, $value, $load); }
/** * Returns the result of filtering $value * * @param string $value * @return string */ public function outputFilter($value) { $filterInput = new Zend_Filter_LocalizedToNormalized(array('date_format' => Varien_Date::DATE_INTERNAL_FORMAT, 'locale' => $this->_locale)); $filterInternal = new Zend_Filter_NormalizedToLocalized(array('date_format' => $this->_dateFormat, 'locale' => $this->_locale)); $value = $filterInput->filter($value); $value = $filterInternal->filter($value); return $value; }
/** * Convert date from localized to internal format * * @param string $date * @param string $locale * @return string */ protected function _convertDate($date, $locale) { $filterInput = new Zend_Filter_LocalizedToNormalized(array('date_format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT))); $filterInternal = new Zend_Filter_NormalizedToLocalized(array('date_format' => Varien_Date::DATE_INTERNAL_FORMAT)); $date = $filterInput->filter($date); $date = $filterInternal->filter($date); return $date; }
/** * Returns the result of filtering $value * * @param string $value * @return string */ public function outputFilter($value) { $filterInput = new \Zend_Filter_LocalizedToNormalized(['date_format' => DateTime::DATE_INTERNAL_FORMAT, 'locale' => $this->localeResolver->getLocale()]); $filterInternal = new \Zend_Filter_NormalizedToLocalized(['date_format' => $this->_dateFormat, 'locale' => $this->localeResolver->getLocale()]); $value = $filterInput->filter($value); $value = $filterInternal->filter($value); return $value; }
public function filterDateValue($value) { $filterInput = new Zend_Filter_LocalizedToNormalized(array('date_format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT))); $filterInternal = new Zend_Filter_NormalizedToLocalized(array('date_format' => Varien_Date::DATE_INTERNAL_FORMAT)); $value = $filterInput->filter($value); $value = $filterInternal->filter($value); return $value; }
/** * Add product to shopping cart action * Overides the addAction() function from Mage_Checkout_CartController. */ public function addAction() { $cart = $this->_getCart(); $params = $this->getRequest()->getParams(); try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $product = $this->_initProduct(); $related = $this->getRequest()->getParam('related_product'); /** * Check product availability */ if (!$product) { $this->_goBack(); return; } $cart->addProduct($product, $params); if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } $cart->save(); $this->_getSession()->setCartWasUpdated(true); /** * @todo remove wishlist observer processAddToCart */ Mage::dispatchEvent('checkout_cart_add_product_complete', array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$this->_getSession()->getNoCartRedirect(true)) { //Remove the added to cart message by calling the isDisplayMsg() function with && logic operator if (!$cart->getQuote()->getHasError() && $this->isDisplayMsg()) { $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName())); $this->_getSession()->addSuccess($message); } $this->_goBack(); } } catch (Mage_Core_Exception $e) { if ($this->_getSession()->getUseNotice(true)) { $this->_getSession()->addNotice(Mage::helper('core')->escapeHtml($e->getMessage())); } else { $messages = array_unique(explode("\n", $e->getMessage())); foreach ($messages as $message) { $this->_getSession()->addError(Mage::helper('core')->escapeHtml($message)); } } $url = $this->_getSession()->getRedirectUrl(true); if ($url) { $this->getResponse()->setRedirect($url); } else { $this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl()); } } catch (Exception $e) { $this->_getSession()->addException($e, $this->__('Cannot add the item to shopping cart.')); Mage::logException($e); $this->_goBack(); } }
public function save() { $price = trim(str_replace(array(Core_Model_Language::getCurrencySymbol(), ' '), '', $this->getData('price'))); $filter = new Zend_Filter_LocalizedToNormalized(); $filter->setOptions(array('locale' => Zend_Registry::get('Zend_Locale'))); $this->setData('price', $filter->filter($price)); parent::save(); return $this; }
public function updateItemOptionsAction() { if (!$this->getRequest()->isXmlHttpRequest()) { return parent::updateItemOptionsAction(); } $message = ''; $cart = $this->_getCart(); $id = (int) $this->getRequest()->getParam('id'); $params = $this->getRequest()->getParams(); if (!isset($params['options'])) { $params['options'] = array(); } try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $quoteItem = $cart->getQuote()->getItemById($id); if (!$quoteItem) { //Mage::throwException($this->__('Quote item is not found.')); return; } $item = $cart->updateItem($id, new Varien_Object($params)); if (is_string($item)) { //Mage::throwException($item); return; } if ($item->getHasError()) { //Mage::throwException($item->getMessage()); return; } $related = $this->getRequest()->getParam('related_product'); if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } $cart->save(); $this->_getSession()->setCartWasUpdated(true); Mage::dispatchEvent('checkout_cart_update_item_complete', array('item' => $item, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$cart->getQuote()->getHasError()) { $message = $this->__('<span><strong>%s</strong> was added to your shopping cart.</span><br /><p><a class="simple-button" href="%s">Continue Shopping</a><span> or </span><a class="button" href="%s">Checkout</a></p>', Mage::helper('core')->escapeHtml($item->getProduct()->getName()), 'javascript:weltpixel.lightbox.close()', Mage::helper('checkout/url')->getCheckoutUrl()); } } catch (Mage_Core_Exception $e) { $message = Mage::helper('core')->escapeHtml($e->getMessage()); } catch (Exception $e) { $message = $this->__('Cannot update the item.'); Mage::logException($e); } $this->loadLayout(); $body = array('message' => $message, 'blocks' => array()); if ($this->getLayout()->getBlock('cart_sidebar')) { $body['blocks']['cart_sidebar'] = array('class' => Mage::helper('weltpixel_quickview')->isMageEnterprise() ? 'top-cart' : 'block-cart', 'content' => preg_replace('/\\/uenc\\/[^\\/]*/', '', $this->getLayout()->getBlock('cart_sidebar')->toHtml())); } if ($this->getLayout()->getBlock('quick_access')) { $body['blocks']['quick_access'] = array('id' => 'quick-access', 'content' => preg_replace('/\\/uenc\\/[^\\/]*/', '', $this->getLayout()->getBlock('quick_access')->toHtml())); } $this->getResponse()->setHeader('Content-Type', 'application/json', true)->setBody(Mage::helper('core')->jsonEncode($body)); }
/** * Add product to shopping cart action * * @return void */ public function execute() { $params = $this->getRequest()->getParams(); try { if (isset($params['qty'])) { $filter = new \Zend_Filter_LocalizedToNormalized(array('locale' => $this->_objectManager->get('Magento\\Framework\\Locale\\ResolverInterface')->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $product = $this->_initProduct(); $related = $this->getRequest()->getParam('related_product'); /** * Check product availability */ if (!$product) { $this->_goBack(); return; } $this->cart->addProduct($product, $params); if (!empty($related)) { $this->cart->addProductsByIds(explode(',', $related)); } $this->cart->save(); $this->_checkoutSession->setCartWasUpdated(true); /** * @todo remove wishlist observer processAddToCart */ $this->_eventManager->dispatch('checkout_cart_add_product_complete', array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$this->_checkoutSession->getNoCartRedirect(true)) { if (!$this->cart->getQuote()->getHasError()) { $message = __('You added %1 to your shopping cart.', $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($product->getName())); $this->messageManager->addSuccess($message); } $this->_goBack(); } } catch (\Magento\Framework\Model\Exception $e) { if ($this->_checkoutSession->getUseNotice(true)) { $this->messageManager->addNotice($this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($e->getMessage())); } else { $messages = array_unique(explode("\n", $e->getMessage())); foreach ($messages as $message) { $this->messageManager->addError($this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($message)); } } $url = $this->_checkoutSession->getRedirectUrl(true); if ($url) { $this->getResponse()->setRedirect($url); } else { $cartUrl = $this->_objectManager->get('Magento\\Checkout\\Helper\\Cart')->getCartUrl(); $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($cartUrl)); } } catch (\Exception $e) { $this->messageManager->addException($e, __('We cannot add this item to your shopping cart')); $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e); $this->_goBack(); } }
/** * Processes localized qty (entered by user at frontend) into internal php format * * @param string $qty * @return float|int|null */ protected function _processLocalizedQty($qty) { if (!$this->_localFilter) { $this->_localFilter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); } $qty = $this->_localFilter->filter($qty); if ($qty < 0) { $qty = null; } return $qty; }
/** * Process localized quantity to internal format * * @param float $qty * @return array|string */ public function process($qty) { if (!$this->localFilter) { $this->localFilter = new \Zend_Filter_LocalizedToNormalized(array('locale' => $this->localeResolver->getLocaleCode())); } $qty = $this->localFilter->filter((double) $qty); if ($qty < 0) { $qty = null; } return $qty; }
public function processProduct() { Mage::log("Processing Product"); $cart = $this->_getCart(); $params = $this->getRequest()->getParams(); if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $_product = $this->_initProduct(); Mage::log("Product SKU : " . $_product->getSku()); $related = $this->getRequest()->getParam('related_product'); $cart->addProduct($_product, $params); return $_product; }
protected function _filterDates($array, $dateFields) { if (empty($dateFields)) { return $array; } $filterInput = new Zend_Filter_LocalizedToNormalized(array('date_format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT))); $filterInternal = new Zend_Filter_NormalizedToLocalized(array('date_format' => Varien_Date::DATE_INTERNAL_FORMAT)); foreach ($dateFields as $dateField) { if (array_key_exists($dateField, $array) && !empty($dateField)) { $array[$dateField] = $filterInput->filter($array[$dateField]); $array[$dateField] = $filterInternal->filter($array[$dateField]); } } return $array; }
/** * Add product to shopping cart action, from a styla script request * * @return Mage_Core_Controller_Varien_Action * @throws Exception */ public function addAction() { $cart = $this->_getCart(); $params = $this->getRequest()->getParams(); try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $product = $this->_initProduct(); /** * Check product availability */ if (!$product) { throw new Exception('Error initializing product.'); } $cart->addProduct($product, $params)->save(); $this->_getSession()->setCartWasUpdated(true); Mage::dispatchEvent('checkout_cart_add_product_complete', array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$this->_getSession()->getNoCartRedirect(true)) { if ($cart->getQuote()->getHasError()) { throw new Exception("Quote error."); } } } catch (Mage_Core_Exception $e) { /** * TODO: we should be returning the error messages back to user */ /* $messages = array_unique(explode("\n", $e->getMessage())); foreach ($messages as $message) { $this->_getSession()->addError(Mage::helper('core')->escapeHtml($message)); } */ Mage::logException($e); $this->getResponse()->setHeader('HTTP/1.0', '500', true); if ($e->getMessage()) { $this->getResponse()->setBody(json_encode($e->getMessage())); } return; } catch (Exception $e) { Mage::logException($e); $this->getResponse()->setHeader('HTTP/1.0', '500', true); return; } $resultArray = array('html' => $this->_getCartHtmlContent(), 'meta' => $this->_getCartMetaData()); $this->getResponse()->setHeader('Content-type', 'application/json'); $this->getResponse()->setBody(json_encode($resultArray)); return; }
/** * (non-PHPdoc) * @see library/Oara/Network/Oara_Network_Publisher_Interface#getTransactionList($aMerchantIds, $dStartDate, $dEndDate) */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $totalTransactions = array(); $filter = new Zend_Filter_LocalizedToNormalized(array('precision' => 2)); $number = self::returnApiData("https://api.clickbank.com/rest/1.3/orders/count?startDate=" . $dStartDate->toString("yyyy-MM-dd") . "&endDate=" . $dEndDate->toString("yyyy-MM-dd")); if ($number[0] != 0) { $transactionXMLList = self::returnApiData("https://api.clickbank.com/rest/1.3/orders/list?startDate=" . $dStartDate->toString("yyyy-MM-dd") . "&endDate=" . $dEndDate->toString("yyyy-MM-dd")); foreach ($transactionXMLList as $transactionXML) { $transactionXML = simplexml_load_string($transactionXML, null, LIBXML_NOERROR | LIBXML_NOWARNING); foreach ($transactionXML->orderData as $singleTransaction) { $transaction = array(); $transaction['merchantId'] = 1; $transactionDate = new Zend_Date(self::findAttribute($singleTransaction, 'date'), 'yyyy-MM-ddTHH:mm:ss'); $transaction['date'] = $transactionDate->toString("yyyy-MM-dd HH:mm:ss"); unset($transactionDate); if (self::findAttribute($singleTransaction, 'affi') != null) { $transaction['custom_id'] = self::findAttribute($singleTransaction, 'affi'); } $transaction['unique_id'] = self::findAttribute($singleTransaction, 'receipt'); $transaction['amount'] = (double) $filter->filter(self::findAttribute($singleTransaction, 'amount')); $transaction['commission'] = (double) $filter->filter(self::findAttribute($singleTransaction, 'amount')); //if (self::findAttribute($singleTransaction, 'txnType') == 'RFND'){ // $transaction['status'] = Oara_Utilities::STATUS_DECLINED; //} else { $transaction['status'] = Oara_Utilities::STATUS_CONFIRMED; //} $totalTransactions[] = $transaction; } } } return $totalTransactions; }
public function processTiercomFixedRates($vendor, $serialize = false) { $tiercomRates = $vendor->getData('tiercom_fixed_rates'); if (is_string($tiercomRates)) { $tiercomRates = unserialize($tiercomRates); } if (!is_array($tiercomRates)) { $tiercomRates = array(); } $udtcFixedConfig = $tiercomRates; if (is_array($udtcFixedConfig) && !empty($udtcFixedConfig) && !empty($udtcFixedConfig['limit']) && is_array($udtcFixedConfig['limit'])) { reset($udtcFixedConfig['limit']); $firstTitleKey = key($udtcFixedConfig['limit']); if (!is_numeric($firstTitleKey)) { $newudtcFixedConfig = array(); $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); foreach ($udtcFixedConfig['limit'] as $_k => $_t) { if (($_limit = $filter->filter($udtcFixedConfig['limit'][$_k])) && false !== ($_value = $filter->filter($udtcFixedConfig['value'][$_k]))) { $_limit = is_numeric($_limit) ? $_limit : '*'; $_sk = is_numeric($_limit) ? $_limit : '9999999999'; $_sk = 'str' . str_pad((string) $_sk, 20, '0', STR_PAD_LEFT); $newudtcFixedConfig[$_sk] = array('limit' => $_limit, 'value' => $_value); } } ksort($newudtcFixedConfig); $newudtcFixedConfig = array_values($newudtcFixedConfig); $tiercomRates = array_values($newudtcFixedConfig); } } if ($serialize) { if (is_array($tiercomRates)) { $tiercomRates = serialize($tiercomRates); } } else { if (is_string($tiercomRates)) { $tiercomRates = unserialize($tiercomRates); } if (!is_array($tiercomRates)) { $tiercomRates = array(); } } $vendor->setData('tiercom_fixed_rates', $tiercomRates); }
protected function _beforeSave() { $udtcFixedConfig = $this->getValue(); if (is_array($udtcFixedConfig) && !empty($udtcFixedConfig) && !empty($udtcFixedConfig['limit']) && is_array($udtcFixedConfig['limit'])) { reset($udtcFixedConfig['limit']); $firstTitleKey = key($udtcFixedConfig['limit']); if (!is_numeric($firstTitleKey)) { $newudtcFixedConfig = array(); $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); foreach ($udtcFixedConfig['limit'] as $_k => $_t) { if (($_limit = $filter->filter($udtcFixedConfig['limit'][$_k])) && false !== ($_value = $filter->filter($udtcFixedConfig['value'][$_k]))) { $_limit = is_numeric($_limit) ? $_limit : '*'; $_sk = is_numeric($_limit) ? $_limit : '9999999999'; $_sk = 'str' . str_pad((string) $_sk, 20, '0', STR_PAD_LEFT); $newudtcFixedConfig[$_sk] = array('limit' => $_limit, 'value' => $_value); } } ksort($newudtcFixedConfig); $newudtcFixedConfig = array_values($newudtcFixedConfig); $this->setValue(array_values($newudtcFixedConfig)); } } return parent::_beforeSave(); }
/** * Convert date from localized to internal format * * @param string $value * @return string */ public function filter($value) { return $this->_normalToLocalFilter->filter($this->_localToNormalFilter->filter($value)); }
/** * ZF-6532 */ public function testLongNumbers() { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => 'de', 'precision' => 0)); $this->assertEquals('1000000', $filter->filter('1.000.000,00')); $this->assertEquals('10000', $filter->filter(10000)); $this->assertEquals(array('date_format' => 'dd.MM.y', 'locale' => 'de', 'day' => '1', 'month' => '2', 'year' => '4'), $filter->filter('1,2.4')); }
/** * Minicart ajax update qty action */ public function ajaxUpdateAction() { if (!$this->_validateFormKey()) { Mage::throwException('Invalid form key'); } $id = (int) $this->getRequest()->getParam('id'); $qty = $this->getRequest()->getParam('qty'); $result = array(); if ($id) { try { $cart = $this->_getCart(); if (isset($qty)) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $qty = $filter->filter($qty); } $quoteItem = $cart->getQuote()->getItemById($id); if (!$quoteItem) { Mage::throwException($this->__('Quote item is not found.')); } if ($qty == 0) { $cart->removeItem($id); } else { $quoteItem->setQty($qty)->save(); } $this->_getCart()->save(); $this->loadLayout(); $result['content'] = $this->getLayout()->getBlock('minicart_content')->toHtml(); $result['qty'] = $this->_getCart()->getSummaryQty(); if (!$quoteItem->getHasError()) { $result['message'] = $this->__('Item was updated successfully.'); } else { $result['notice'] = $quoteItem->getMessage(); } $result['success'] = 1; } catch (Exception $e) { $result['success'] = 0; $result['error'] = $this->__('Can not save item.'); } } $this->getResponse()->setHeader('Content-type', 'application/json'); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); }
public function saveAction() { if (!$this->_validateProducts()) { return; } /* Collect Data */ $inventoryData = $this->getRequest()->getParam('inventory', array()); $attributesData = $this->getRequest()->getParam('attributes', array()); $websiteRemoveData = $this->getRequest()->getParam('remove_website_ids', array()); $websiteAddData = $this->getRequest()->getParam('add_website_ids', array()); /* Prepare inventory data item options (use config settings) */ foreach (Mage::helper('Mage_CatalogInventory_Helper_Data')->getConfigItemOptions() as $option) { if (isset($inventoryData[$option]) && !isset($inventoryData['use_config_' . $option])) { $inventoryData['use_config_' . $option] = 0; } } try { if ($attributesData) { $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); $storeId = $this->_getHelper()->getSelectedStoreId(); foreach ($attributesData as $attributeCode => $value) { $attribute = Mage::getSingleton('Mage_Eav_Model_Config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode); if (!$attribute->getAttributeId()) { unset($attributesData[$attributeCode]); continue; } if ($attribute->getBackendType() == 'datetime') { if (!empty($value)) { $filterInput = new Zend_Filter_LocalizedToNormalized(array('date_format' => $dateFormat)); $filterInternal = new Zend_Filter_NormalizedToLocalized(array('date_format' => Varien_Date::DATE_INTERNAL_FORMAT)); $value = $filterInternal->filter($filterInput->filter($value)); } else { $value = null; } $attributesData[$attributeCode] = $value; } else { if ($attribute->getFrontendInput() == 'multiselect') { if (is_array($value)) { $value = implode(',', $value); } $attributesData[$attributeCode] = $value; } } } Mage::getSingleton('Mage_Catalog_Model_Product_Action')->updateAttributes($this->_getHelper()->getProductIds(), $attributesData, $storeId); } if ($inventoryData) { $stockItem = Mage::getModel('Mage_CatalogInventory_Model_Stock_Item'); $stockItem->setProcessIndexEvents(false); $stockItemSaved = false; foreach ($this->_getHelper()->getProductIds() as $productId) { $stockItem->setData(array()); $stockItem->loadByProduct($productId)->setProductId($productId); $stockDataChanged = false; foreach ($inventoryData as $k => $v) { $stockItem->setDataUsingMethod($k, $v); if ($stockItem->dataHasChangedFor($k)) { $stockDataChanged = true; } } if ($stockDataChanged) { $stockItem->save(); $stockItemSaved = true; } } if ($stockItemSaved) { Mage::getSingleton('Mage_Index_Model_Indexer')->indexEvents(Mage_CatalogInventory_Model_Stock_Item::ENTITY, Mage_Index_Model_Event::TYPE_SAVE); } } if ($websiteAddData || $websiteRemoveData) { /* @var $actionModel Mage_Catalog_Model_Product_Action */ $actionModel = Mage::getSingleton('Mage_Catalog_Model_Product_Action'); $productIds = $this->_getHelper()->getProductIds(); if ($websiteRemoveData) { $actionModel->updateWebsites($productIds, $websiteRemoveData, 'remove'); } if ($websiteAddData) { $actionModel->updateWebsites($productIds, $websiteAddData, 'add'); } Mage::dispatchEvent('catalog_product_to_website_change', array('products' => $productIds)); $this->_getSession()->addNotice($this->__('Please refresh "Catalog URL Rewrites" and "Product Attributes" in System -> <a href="%s">Index Management</a>', $this->getUrl('adminhtml/process/list'))); } $this->_getSession()->addSuccess($this->__('Total of %d record(s) were updated', count($this->_getHelper()->getProductIds()))); } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()); } catch (Exception $e) { $this->_getSession()->addException($e, $this->__('An error occurred while updating the product(s) attributes.')); } $this->_redirect('*/catalog_product/', array('store' => $this->_getHelper()->getSelectedStoreId())); }
/** * Prepare data for save * * @return Mage_Eav_Model_Entity_Attribute * @throws Mage_Eav_Exception */ protected function _beforeSave() { /** * Check for maximum attribute_code length */ if (isset($this->_data['attribute_code']) && !Zend_Validate::is($this->_data['attribute_code'], 'StringLength', array('max' => self::ATTRIBUTE_CODE_MAX_LENGTH))) { throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Maximum length of attribute code must be less then %s symbols', self::ATTRIBUTE_CODE_MAX_LENGTH)); } $defaultValue = $this->getDefaultValue(); $hasDefaultValue = (string) $defaultValue != ''; if ($this->getBackendType() == 'decimal' && $hasDefaultValue) { $locale = Mage::app()->getLocale()->getLocaleCode(); if (!Zend_Locale_Format::isNumber($defaultValue, array('locale' => $locale))) { throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default decimal value')); } try { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $this->setDefaultValue($filter->filter($defaultValue)); } catch (Exception $e) { throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default decimal value')); } } if ($this->getBackendType() == 'datetime') { if (!$this->getBackendModel()) { $this->setBackendModel('eav/entity_attribute_backend_datetime'); } if (!$this->getFrontendModel()) { $this->setFrontendModel('eav/entity_attribute_frontend_datetime'); } // save default date value as timestamp if ($hasDefaultValue) { $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); try { $defaultValue = Mage::app()->getLocale()->date($defaultValue, $format, null, false)->toValue(); $this->setDefaultValue($defaultValue); } catch (Exception $e) { throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default date')); } } } if ($this->getBackendType() == 'gallery') { if (!$this->getBackendModel()) { $this->setBackendModel('eav/entity_attribute_backend_media'); } } return parent::_beforeSave(); }
/** * Apply normalization filter to item qty value * * @param int $itemQty * @return int|array */ protected function normalize($itemQty) { if ($itemQty) { $filter = new \Zend_Filter_LocalizedToNormalized(['locale' => $this->resolver->getLocale()]); return $filter->filter($itemQty); } return $itemQty; }
/** * Update product configuration for a cart item */ public function updateItemOptionsAction() { $cart = $this->_getCart(); $id = (int) $this->getRequest()->getParam('id'); $params = $this->getRequest()->getParams(); if (!isset($params['options'])) { $params['options'] = array(); } try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $quoteItem = $cart->getQuote()->getItemById($id); if (!$quoteItem) { $this->_message($this->__('Quote item is not found.'), parent::MESSAGE_STATUS_ERROR); return; } $item = $cart->updateItem($id, new Varien_Object($params)); if (is_string($item)) { Mage::throwException($item); } if ($item->getHasError()) { Mage::throwException($item->getMessage()); } $related = $this->getRequest()->getParam('related_product'); if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } $cart->save(); $this->_getSession()->setCartWasUpdated(true); Mage::dispatchEvent('checkout_cart_update_item_complete', array('item' => $item, 'request' => $this->getRequest(), 'response' => $this->getResponse())); $productName = Mage::helper('core')->escapeHtml($item->getProduct()->getName()); $message = $this->__('%s was updated in your shopping cart.', $productName); if ($cart->getQuote()->getHasError()) { $message .= $this->__(' But cart has some errors.'); } $this->_message($message, parent::MESSAGE_STATUS_SUCCESS); } catch (Mage_Core_Exception $e) { if ($this->_getSession()->getUseNotice(true)) { $this->_message($e->getMessage(), parent::MESSAGE_STATUS_ERROR); } else { $messageText = implode("\n", array_unique(explode("\n", $e->getMessage()))); $this->_message($messageText, parent::MESSAGE_STATUS_ERROR); } } catch (Exception $e) { Mage::logException($e); $this->_message($this->__('Cannot update the item.'), self::MESSAGE_STATUS_ERROR); } }
public function changeqtycartitemAction() { $result = array(); $result['error'] = false; if (($result['qty'] = $this->getRequest()->getParam('qty')) && ($result['item_id'] = $this->getRequest()->getParam('item_id'))) { try { $cartData = array(); $cartData[$result['item_id']] = array('qty' => $result['qty']); $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); foreach ($cartData as $index => $data) { if (isset($data['qty'])) { $cartData[$index]['qty'] = $filter->filter($data['qty']); } } $cart = Mage::getSingleton('checkout/cart'); if (!$cart->getCustomerSession()->getCustomer()->getId() && $cart->getQuote()->getCustomerId()) { $cart->getQuote()->setCustomerId(null); } $item = $cart->getQuote()->getItemById($result['item_id']); $product = Mage::getModel('catalog/product')->load($item->getProductId()); if ($product->getStockItem()->getManageStock()) { $maximumQty = intval($product->getStockItem()->getMaxSaleQty()); $minimumQty = intval($product->getStockItem()->getMinSaleQty()); if ($result['qty'] > $maximumQty) { $result['error'] = true; $result['message'] = $this->__('The maximum quantity allowed for purchase is %s.', $maximumQty); } elseif ($result['qty'] < $minimumQty) { $result['error'] = true; $result['message'] = $this->__('The minimum quantity allowed for purchase is %s.', $minimumQty); } else { if ($item->getHasChildren()) { foreach ($item->getChildren() as $child) { $_product_id = $child->getProductId(); $_product = Mage::getModel('catalog/product')->load($_product_id); $maximumQty = $_product->getStockItem()->getQty(); if ($result['qty'] > $maximumQty) { $result['error'] = true; $result['message'] = $this->__('The requested quantity for %s is not available.', '"' . $product->getName() . '"'); break; } } } else { $maximumQty = $product->getStockItem()->getQty(); if ($result['qty'] > $maximumQty) { $result['error'] = true; $result['message'] = $this->__('The requested quantity for %s is not available.', '"' . $product->getName() . '"'); } } } } if (!$result['error']) { if (method_exists($cart, 'suggestItemsQty')) { $cartData = $cart->suggestItemsQty($cartData); } $cart->updateItems($cartData)->save(); Mage::getSingleton('checkout/session')->setCartWasUpdated(true); } } catch (Mage_Core_Exception $e) { $result['error'] = true; $result['message'] = $e->getMessage(); } catch (Exception $e) { $result['error'] = true; $result['message'] = $this->__('Cannot update shopping cart.'); Mage::logException($e); } if (!$result['error'] && $this->getRequest()->getParam('sidebar') == 1) { $layout = Mage::getSingleton('core/layout'); $result['cart'] = $layout->createBlock('checkout/cart_sidebar', 'cart_sidebar')->setTemplate('checkout/cart/sidebar.phtml')->addItemRender('simple', 'checkout/cart_item_renderer', 'checkout/cart/sidebar/default.phtml')->addItemRender('configurable', 'checkout/cart_item_renderer_configurable', 'checkout/cart/sidebar/default.phtml')->addItemRender('grouped', 'checkout/cart_item_renderer_grouped', 'checkout/cart/sidebar/default.phtml')->addItemRender('bundle', 'bundle/checkout_cart_item_renderer', 'checkout/cart/sidebar/default.phtml')->renderView(); } if (!$result['error'] && $this->getRequest()->getParam('cart') == 1) { if ($item_html = $this->getCartItem($result['item_id'])) { $result['item_html'] = $item_html; } if ($total = $this->getCartTolal()) { $result['total'] = $total; } } if (!$result['error']) { $result['top_links'] = Mage::getModel('adodis_ajaxcart/observer')->getTopLinks(); } } else { $result['error'] = true; $result['message'] = $this->__('The requested quantity is not available.'); } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); }