public function sendAction() { $product = $this->_initProduct(); $this->_initSendToFriendModel(); if (!$product || !$product->isVisibleInCatalog()) { $this->_forward('noRoute'); return; } $productHelper = AO::helper('catalog/product'); $sendToFriendModel = AO::registry('send_to_friend_model'); /** * check if user is allowed to send product to a friend */ if (!$sendToFriendModel->canEmailToFriend()) { AO::getSingleton('catalog/session')->addError($this->__('You cannot email this product to a friend')); $this->_redirectReferer($product->getProductUrl()); return; } $maxSendsToFriend = $sendToFriendModel->getMaxSendsToFriend(); if ($maxSendsToFriend) { AO::getSingleton('catalog/session')->addNotice($this->__('You cannot send more than %d times in an hour', $maxSendsToFriend)); } $this->loadLayout(); $this->_initLayoutMessages('catalog/session'); $this->renderLayout(); AO::dispatchEvent('sendfriend_product', array('product' => $product)); }
public function getJsonConfig() { AO::app()->getLocale()->getJsPriceFormat(); $store = AO::app()->getStore(); $optionsArray = $this->getOptions(); $options = array(); $selected = array(); foreach ($optionsArray as $_option) { if (!$_option->getSelections()) { continue; } $option = array('selections' => array(), 'isMulti' => $_option->getType() == 'multi' || $_option->getType() == 'checkbox'); $selectionCount = count($_option->getSelections()); foreach ($_option->getSelections() as $_selection) { $_qty = !($_selection->getSelectionQty() * 1) ? '1' : $_selection->getSelectionQty() * 1; $selection = array('qty' => $_qty, 'customQty' => $_selection->getSelectionCanChangeQty(), 'price' => AO::helper('core')->currency($_selection->getFinalPrice(), false, false), 'priceValue' => AO::helper('core')->currency($_selection->getSelectionPriceValue(), false, false), 'priceType' => $_selection->getSelectionPriceType(), 'tierPrice' => $_selection->getTierPrice(), 'plusDisposition' => 0, 'minusDisposition' => 0); $responseObject = new Varien_Object(); $args = array('response_object' => $responseObject, 'selection' => $_selection); AO::dispatchEvent('bundle_product_view_config', $args); if (is_array($responseObject->getAdditionalOptions())) { foreach ($responseObject->getAdditionalOptions() as $o => $v) { $selection[$o] = $v; } } $option['selections'][$_selection->getSelectionId()] = $selection; if (($_selection->getIsDefault() || $selectionCount == 1 && $_option->getRequired()) && $_selection->isSalable()) { $selected[$_option->getId()][] = $_selection->getSelectionId(); } } $options[$_option->getId()] = $option; } $config = array('options' => $options, 'selected' => $selected, 'bundleId' => $this->getProduct()->getId(), 'priceFormat' => AO::app()->getLocale()->getJsPriceFormat(), 'basePrice' => AO::helper('core')->currency($this->getProduct()->getPrice(), false, false), 'priceType' => $this->getProduct()->getPriceType(), 'specialPrice' => $this->getProduct()->getSpecialPrice()); return Zend_Json::encode($config); }
/** * Initialize and check product * * @return Mage_Catalog_Model_Product */ protected function _initProduct() { AO::dispatchEvent('review_controller_product_init_before', array('controller_action' => $this)); $categoryId = (int) $this->getRequest()->getParam('category', false); $productId = (int) $this->getRequest()->getParam('id'); if (!$productId) { return false; } $product = AO::getModel('catalog/product')->setStoreId(AO::app()->getStore()->getId())->load($productId); /* @var $product Mage_Catalog_Model_Product */ if (!$product->getId() || !$product->isVisibleInCatalog() || !$product->isVisibleInSiteVisibility()) { return false; } if ($categoryId) { $category = AO::getModel('catalog/category')->load($categoryId); AO::register('current_category', $category); } AO::register('current_product', $product); AO::register('product', $product); try { AO::dispatchEvent('review_controller_product_init', array('product' => $product)); AO::dispatchEvent('review_controller_product_init_after', array('product' => $product, 'controller_action' => $this)); } catch (Mage_Core_Exception $e) { AO::logException($e); return false; } return $product; }
/** * Clean logs * * @param Mage_Log_Model_Log $object * @return Mage_Log_Model_Mysql4_Log */ public function clean(Mage_Log_Model_Log $object) { $cleanTime = $object->getLogCleanTime(); AO::dispatchEvent('log_log_clean_before', array('log' => $object)); $this->_cleanVisitors($cleanTime); $this->_cleanCustomers($cleanTime); $this->_cleanUrls(); AO::dispatchEvent('log_log_clean_after', array('log' => $object)); return $this; }
protected function _getAdditionalElementTypes() { $result = array('price' => AO::getConfig()->getBlockClassName('adminhtml/catalog_product_helper_form_price'), 'image' => AO::getConfig()->getBlockClassName('adminhtml/catalog_product_helper_form_image'), 'boolean' => AO::getConfig()->getBlockClassName('adminhtml/catalog_product_helper_form_boolean')); $response = new Varien_Object(); $response->setTypes(array()); AO::dispatchEvent('adminhtml_catalog_product_edit_element_types', array('response' => $response)); foreach ($response->getTypes() as $typeName => $typeClass) { $result[$typeName] = $typeClass; } return $result; }
/** * Authenticate customer * * @param string $login * @param string $password * @return true * @throws Exception */ public function authenticate($login, $password) { $this->loadByEmail($login); if ($this->getConfirmation() && $this->isConfirmationRequired()) { throw new Exception(AO::helper('customer')->__('This account is not confirmed.'), self::EXCEPTION_EMAIL_NOT_CONFIRMED); } if (!$this->validatePassword($password)) { throw new Exception(AO::helper('customer')->__('Invalid login or password.'), self::EXCEPTION_INVALID_EMAIL_OR_PASSWORD); } AO::dispatchEvent('customer_customer_authenticated', array('model' => $this, 'password' => $password)); return true; }
/** * Add products to websites * * @param array $websiteIds * @param array $productIds * @return Mage_Catalog_Model_Product_Website */ public function addProducts($websiteIds, $productIds) { try { $this->_getResource()->addProducts($websiteIds, $productIds); $this->_refreshRewrites($productIds); AO::getResourceModel('catalog/category')->refreshProductIndex(array(), $productIds); AO::dispatchEvent('catalog_product_website_update', array('website_ids' => $websiteIds, 'product_ids' => $productIds, 'action' => 'add')); } catch (Exception $e) { AO::throwException(AO::helper('catalog')->__('There was an error while adding products to websites')); } return $this; }
/** * Get product final price * * @param double $qty * @param Mage_Catalog_Model_Product $product * @return double */ public function getFinalPrice($qty = null, $product) { if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) { return $product->getCalculatedFinalPrice(); } $finalPrice = $product->getPrice(); /** * Just product with fixed price calculation has price */ if ($finalPrice) { $finalPrice = $this->_applyTierPrice($product, $qty, $finalPrice); $finalPrice = $this->_applySpecialPrice($product, $finalPrice); $product->setFinalPrice($finalPrice); AO::dispatchEvent('catalog_product_get_final_price', array('product' => $product)); $finalPrice = $product->getData('final_price'); } if ($product->hasCustomOptions()) { $customOption = $product->getCustomOption('bundle_option_ids'); // $optionIds = unserialize($customOption->getValue()); $customOption = $product->getCustomOption('bundle_selection_ids'); $selectionIds = unserialize($customOption->getValue()); $selections = $product->getTypeInstance(true)->getSelectionsByIds($selectionIds, $product); foreach ($selections->getItems() as $selection) { if ($selection->isSalable()) { $selectionQty = $product->getCustomOption('selection_qty_' . $selection->getSelectionId()); if ($selectionQty) { $finalPrice = $finalPrice + $this->getSelectionPrice($product, $selection, $selectionQty->getValue()); } } } } else { // if ($options = $this->getOptions($product)) { // /* some strange thing // foreach ($options as $option) { // $selectionCount = count($option->getSelections()); // if ($selectionCount) { // foreach ($option->getSelections() as $selection) { // if ($selection->isSalable() && ($selection->getIsDefault() || ($option->getRequired() &&)) { // $finalPrice = $finalPrice + $this->getSelectionPrice($product, $selection); // } // } // } // } // */ // } } $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice); $product->setFinalPrice($finalPrice); return max(0, $product->getData('final_price')); }
/** * Get product final price * * @param double $qty * @param Mage_Catalog_Model_Product $product * @return double */ public function getFinalPrice($qty = null, $product) { if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) { return $product->getCalculatedFinalPrice(); } $finalPrice = $product->getPrice(); $finalPrice = $this->_applyTierPrice($product, $qty, $finalPrice); $finalPrice = $this->_applySpecialPrice($product, $finalPrice); $product->setFinalPrice($finalPrice); AO::dispatchEvent('catalog_product_get_final_price', array('product' => $product)); $finalPrice = $product->getData('final_price'); $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice); return max(0, $finalPrice); }
/** * Conigure and start session * * @param string $sessionName * @return Mage_Core_Model_Session_Abstract_Varien */ public function start($sessionName = null) { if (isset($_SESSION)) { return $this; } if (VPROF) { Varien_Profiler::start(__METHOD__ . '/setOptions'); } if (is_writable(AO::getBaseDir('session'))) { session_save_path($this->getSessionSavePath()); } if (VPROF) { Varien_Profiler::stop(__METHOD__ . '/setOptions'); } switch ($this->getSessionSaveMethod()) { case 'db': ini_set('session.save_handler', 'user'); $sessionResource = AO::getResourceSingleton('core/session'); /* @var $sessionResource Mage_Core_Model_Mysql4_Session */ $sessionResource->setSaveHandler(); break; case 'memcache': ini_set('session.save_handler', 'memcache'); session_save_path($this->getSessionSavePath()); break; default: session_module_name('files'); break; } AO::dispatchEvent('core_session_before_set_cookie_params'); // set session cookie params session_set_cookie_params($this->getCookie()->getLifetime(), $this->getCookie()->getPath(), $this->getCookie()->getDomain(), $this->getCookie()->isSecure(), $this->getCookie()->getHttponly()); if (!empty($sessionName)) { session_name($sessionName); } // potential custom logic for session id (ex. switching between hosts) $this->setSessionId(); if (VPROF) { Varien_Profiler::start(__METHOD__ . '/start'); } if ($sessionCacheLimiter = AO::getConfig()->getNode('global/session_cache_limiter')) { session_cache_limiter((string) $sessionCacheLimiter); } session_start(); if (VPROF) { Varien_Profiler::stop(__METHOD__ . '/start'); } return $this; }
protected function _prepareForm() { $this->setFormExcludedFieldList(array('tier_price', 'gallery', 'media_gallery')); AO::dispatchEvent('adminhtml_catalog_product_form_prepare_excluded_field_list', array('object' => $this)); $form = new Varien_Data_Form(); $fieldset = $form->addFieldset('fields', array('legend' => AO::helper('catalog')->__('Attributes'))); $attributes = $this->getAttributes(); /** * Initialize product object as form property * for using it in elements generation */ $form->setDataObject(AO::getModel('catalog/product')); $this->_setFieldset($attributes, $fieldset, $this->getFormExcludedFieldList()); $form->setFieldNameSuffix('attributes'); $this->setForm($form); }
/** * Converting order object to quote object * * @param Mage_Sales_Model_Order $order * @return Mage_Sales_Model_Quote */ public function toQuote(Mage_Sales_Model_Order $order, $quote = null) { if (!$quote instanceof Mage_Sales_Model_Quote) { $quote = AO::getModel('sales/quote'); } $quote->setStoreId($order->getStoreId())->setOrderId($order->getId()); AO::helper('core')->copyFieldset('sales_convert_order', 'to_quote', $order, $quote); // /** // * Customer data // */ // ->setCustomerId($order->getCustomerId()) // ->setCustomerEmail($order->getCustomerEmail()) // ->setCustomerGroupId($order->getCustomerGroupId()) // ->setCustomerTaxClassId($order->getCustomerTaxClassId()) // /** // * Not use note from previos order // */ // //->setCustomerNote($order->getCustomerNote()) // //->setCustomerNoteNotify($order->getCustomerNoteNotify()) // ->setCustomerIsGuest($order->getCustomerIsGuest()) // // /** // * Currency data // */ // ->setBaseCurrencyCode($order->getBaseCurrencyCode()) // ->setStoreCurrencyCode($order->getStoreCurrencyCode()) // ->setQuoteCurrencyCode($order->getOrderCurrencyCode()) // ->setStoreToBaseRate($order->getStoreToBaseRate()) // ->setStoreToQuoteRate($order->getStoreToOrderRate()) // // /** // * Totals data // */ // ->setGrandTotal($order->getGrandTotal()) // ->setBaseGrandTotal($order->getBaseGrandTotal()) // // /** // * Another data // */ // ->setCouponCode($order->getCouponCode()) // ->setGiftcertCode($order->getGiftcertCode()) // ->setAppliedRuleIds($order->getAppliedRuleIds()); // //->collectTotals(); // AO::dispatchEvent('sales_convert_order_to_quote', array('order' => $order, 'quote' => $quote)); return $quote; }
public function getRate() { if (!$this->getCountryId() || !$this->getCustomerClassId() || !$this->getProductClassId()) { return 0; #throw AO::exception('Mage_Tax', AO::helper('tax')->__('Invalid data for tax rate calculation')); } $cacheKey = $this->getCustomerClassId() . '|' . $this->getProductClassId() . '|' . $this->getCountryId() . '|' . $this->getRegionId() . '|' . $this->getPostcode(); if (!isset($this->_cache[$cacheKey])) { $this->unsRateValue(); AO::dispatchEvent('tax_rate_data_fetch', array('request' => $this)); if (!$this->hasRateValue()) { $this->setRateValue($this->_getResource()->fetchRate($this)); } $this->_cache[$cacheKey] = $this->getRateValue(); } return $this->_cache[$cacheKey]; }
/** * Initialize requested category object * * @return Mage_Catalog_Model_Category */ protected function _initCatagory() { AO::dispatchEvent('catalog_controller_category_init_before', array('controller_action' => $this)); $categoryId = (int) $this->getRequest()->getParam('id', false); if (!$categoryId) { return false; } $category = AO::getModel('catalog/category')->setStoreId(AO::app()->getStore()->getId())->load($categoryId); if (!AO::helper('catalog/category')->canShow($category)) { return false; } AO::getSingleton('catalog/session')->setLastVisitedCategoryId($category->getId()); AO::register('current_category', $category); try { AO::dispatchEvent('catalog_controller_category_init_after', array('category' => $category, 'controller_action' => $this)); } catch (Mage_Core_Exception $e) { AO::logException($e); return false; } return $category; }
/** * Remove item from compare list */ public function removeAction() { if ($productId = (int) $this->getRequest()->getParam('product')) { $product = AO::getModel('catalog/product')->setStoreId(AO::app()->getStore()->getId())->load($productId); if ($product->getId()) { $item = AO::getModel('catalog/product_compare_item'); if (AO::getSingleton('customer/session')->isLoggedIn()) { $item->addCustomerData(AO::getSingleton('customer/session')->getCustomer()); } else { $item->addVisitorId(AO::getSingleton('log/visitor')->getId()); } $item->loadByProduct($product); if ($item->getId()) { $item->delete(); AO::getSingleton('catalog/session')->addSuccess($this->__('Product %s successfully removed from compare list', $product->getName())); AO::dispatchEvent('catalog_product_compare_remove_product', array('product' => $item)); AO::helper('catalog/product_compare')->calculate(); } } } $this->_redirectReferer(); }
protected function _prepareData() { $product = AO::registry('product'); /* @var $product Mage_Catalog_Model_Product */ $this->_itemCollection = $product->getUpSellProductCollection()->addAttributeToSort('position', 'asc')->addStoreFilter(); AO::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection, AO::getSingleton('checkout/session')->getQuoteId()); $this->_addProductAttributesAndPrices($this->_itemCollection); // AO::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_itemCollection); AO::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection); if ($this->getItemLimit('upsell') > 0) { $this->_itemCollection->setPageSize($this->getItemLimit('upsell')); } $this->_itemCollection->load(); /** * Updating collection with desired items */ AO::dispatchEvent('catalog_product_upsell', array('product' => $product, 'collection' => $this->_itemCollection, 'limit' => $this->getItemLimit())); foreach ($this->_itemCollection as $product) { $product->setDoNotUseCategoryId(true); } return $this; }
/** * After rule delete * redeclared for dispatch tax_settings_change_after event * * @return Mage_Tax_Model_Calculation_Rule */ protected function _afterDelete() { AO::dispatchEvent('tax_settings_change_after'); return parent::_afterDelete(); }
public function getRate($request) { if (!$request->getCountryId() || !$request->getCustomerClassId() || !$request->getProductClassId()) { return 0; } $cacheKey = "{$request->getProductClassId()}|{$request->getCustomerClassId()}|{$request->getCountryId()}|{$request->getRegionId()}|{$request->getPostcode()}"; if (!isset($this->_rateCache[$cacheKey])) { $this->unsRateValue(); $this->unsCalculationProcess(); $this->unsEventModuleId(); AO::dispatchEvent('tax_rate_data_fetch', array('request' => $this)); if (!$this->hasRateValue()) { $this->setCalculationProcess($this->_getResource()->getCalculationProcess($request)); $this->setRateValue($this->_getResource()->getRate($request)); } else { $this->setCalculationProcess($this->_formCalculationProcess()); } $this->_rateCache[$cacheKey] = $this->getRateValue(); $this->_rateCalculationProcess[$cacheKey] = $this->getCalculationProcess(); } return $this->_rateCache[$cacheKey]; }
/** * Importing store data from osCommerce to Magento * * @param Mage_Oscommerce_Model_Oscommerce $obj */ public function importStores() { $importModel = $this->getImportModel(); $locales = $this->getStoreLocales(); $defaultStore = ''; $storeInformation = $this->getOscStoreInformation(); $defaultStoreCode = $storeInformation['DEFAULT_LANGUAGE']; $configModel = $this->getConfigModel(); $storeModel = $this->getStoreModel(); $storeGroupModel = $this->getStoreGroupModel(); $storeGroupId = $storeGroupModel->getId(); $websiteModel = $this->getWebsiteModel(); $websiteId = $websiteModel->getId(); $storePairs = array(); if ($stores = $this->getOscStores()) { foreach ($stores as $store) { try { $oscStoreId = $store['id']; unset($store['id']); $store['group_id'] = $storeGroupId; $store['website_id'] = $websiteId; $storeModel->unsetData(); $storeModel->setOrigData(); $storeModel->load($store['code']); if ($storeModel->getId() && $storeModel->getCode() == $store['code']) { $localeCode = $locales[$store['code']]; unset($locales[$store['code']]); $store['code'] = $store['code'] . '_' . $websiteId . time(); // for unique store code $locales[$store['code']] = $localeCode; } $store['name'] = $this->convert($store['name']); $storeModel->unsetData(); $storeModel->setOrigData(); $storeModel->setData($store); $storeModel->save(); $storePairs[$oscStoreId] = $storeModel->getId(); $storeLocale = isset($locales[$storeModel->getCode()]) ? $locales[$storeModel->getCode()] : $locales['default']; $configModel->unsetData(); $configModel->setOrigData(); $configModel->setScope('stores')->setScopeId($storeModel->getId())->setPath('general/locale/code')->setValue($storeLocale)->save(); if ($store['scode'] == $defaultStoreCode) { $defaultStore = $storeModel->getId(); } AO::dispatchEvent('store_add', array('store' => $storeModel)); } catch (Exception $e) { //echo $e->getMessage(); } } } if (sizeof($storePairs) > 0) { $this->saveLogs($storePairs, 'store'); } $this->setStoreLocales($locales); if ($defaultStore) { $storeGroupModel->setDefaultStoreId($defaultStore); $storeGroupModel->save(); } AO::app()->reinitStores(); unset($stores); }
public function searchAction() { AO::dispatchEvent('on_view_report', array('report' => 'search')); $this->_initAction()->_setActiveMenu('report/search')->_addBreadcrumb(AO::helper('adminhtml')->__('Search Terms'), AO::helper('adminhtml')->__('Search Terms'))->_addContent($this->getLayout()->createBlock('adminhtml/report_search'))->renderLayout(); }
/** * Generate catalog price rules prices for specified date range * If from date is not defined - will be used previous day by UTC * If to date is not defined - will be used next day by UTC * * @param int|string|null $fromDate * @param int|string|null $toDate * @param int $productId * @return Mage_CatalogRule_Model_Mysql4_Rule */ public function applyAllRulesForDateRange($fromDate = null, $toDate = null, $productId = null) { $write = $this->_getWriteAdapter(); $write->beginTransaction(); AO::dispatchEvent('catalogrule_before_apply', array('resource' => $this)); $clearOldData = false; if ($fromDate === null) { $fromDate = mktime(0, 0, 0, date('m'), date('d') - 1); /** * If fromDate not specified we can delete all data oldest than 1 day * We have run it for clear table in case when cron was not installed * and old data exist in table */ $clearOldData = true; } if (is_string($fromDate)) { $fromDate = strtotime($fromDate); } if ($toDate === null) { $toDate = mktime(0, 0, 0, date('m'), date('d') + 1); } if (is_string($toDate)) { $toDate = strtotime($toDate); } $product = null; if ($productId instanceof Mage_Catalog_Model_Product) { $product = $productId; $productId = $productId->getId(); } $this->removeCatalogPricesForDateRange($fromDate, $toDate, $productId); if ($clearOldData) { $this->deleteOldData($fromDate, $productId); } try { /** * Update products rules prices per each website separatly * because of max join limit in mysql */ foreach (AO::app()->getWebsites(false) as $website) { $productsStmt = $this->_getRuleProductsStmt($fromDate, $toDate, $productId, $website->getId()); $dayPrices = array(); $stopFlags = array(); $prevKey = null; while ($ruleData = $productsStmt->fetch()) { $productId = $ruleData['product_id']; $productKey = $productId . '_' . $ruleData['website_id'] . '_' . $ruleData['customer_group_id']; if ($prevKey && $prevKey != $productKey) { $stopFlags = array(); } /** * Build prices for each day */ for ($time = $fromDate; $time <= $toDate; $time += self::SECONDS_IN_DAY) { if (($ruleData['from_time'] == 0 || $time >= $ruleData['from_time']) && ($ruleData['to_time'] == 0 || $time <= $ruleData['to_time'])) { $priceKey = $time . '_' . $productKey; if (isset($stopFlags[$priceKey])) { continue; } if (!isset($dayPrices[$priceKey])) { $dayPrices[$priceKey] = array('rule_date' => $time, 'website_id' => $ruleData['website_id'], 'customer_group_id' => $ruleData['customer_group_id'], 'product_id' => $productId, 'rule_price' => $this->_calcRuleProductPrice($ruleData), 'latest_start_date' => $ruleData['from_time'], 'earliest_end_date' => $ruleData['to_time']); } else { $dayPrices[$priceKey]['rule_price'] = $this->_calcRuleProductPrice($ruleData, $dayPrices[$priceKey]); $dayPrices[$priceKey]['latest_start_date'] = max($dayPrices[$priceKey]['latest_start_date'], $ruleData['from_time']); $dayPrices[$priceKey]['earliest_end_date'] = min($dayPrices[$priceKey]['earliest_end_date'], $ruleData['to_time']); } if ($ruleData['action_stop']) { $stopFlags[$priceKey] = true; } } } $prevKey = $productKey; if (count($dayPrices) > 100) { $this->_saveRuleProductPrices($dayPrices); $dayPrices = array(); } } $this->_saveRuleProductPrices($dayPrices); } $this->_saveRuleProductPrices($dayPrices); $write->commit(); // // $dayPrices = array(); // $stopFlags = array(); // $prevKey = null; // while ($ruleData = $productsStmt->fetch()) { // $productId = $ruleData['product_id']; // $productKey= $productId . '_' . $ruleData['website_id'] . '_' . $ruleData['customer_group_id']; // // if ($prevKey && ($prevKey != $productKey)) { // $stopFlags = array(); // } // // /** // * Build prices for each day // */ // for ($time=$fromDate; $time<=$toDate; $time+=self::SECONDS_IN_DAY) { // // if (($ruleData['from_time']==0 || $time >= $ruleData['from_time']) // && ($ruleData['to_time']==0 || $time <=$ruleData['to_time'])) { // // $priceKey = $time . '_' . $productKey; // // if (isset($stopFlags[$priceKey])) { // continue; // } // // if (!isset($dayPrices[$priceKey])) { // $dayPrices[$priceKey] = array( // 'rule_date' => $time, // 'website_id' => $ruleData['website_id'], // 'customer_group_id' => $ruleData['customer_group_id'], // 'product_id' => $productId, // 'rule_price' => $this->_calcRuleProductPrice($ruleData), // 'latest_start_date' => $ruleData['from_time'], // 'earliest_end_date' => $ruleData['to_time'], // ); // } // else { // $dayPrices[$priceKey]['rule_price'] = $this->_calcRuleProductPrice( // $ruleData, // $dayPrices[$priceKey] // ); // $dayPrices[$priceKey]['latest_start_date'] = max( // $dayPrices[$priceKey]['latest_start_date'], // $ruleData['from_time'] // ); // $dayPrices[$priceKey]['earliest_end_date'] = min( // $dayPrices[$priceKey]['earliest_end_date'], // $ruleData['to_time'] // ); // } // // if ($ruleData['action_stop']) { // $stopFlags[$priceKey] = true; // } // } // } // // $prevKey = $productKey; // // if (count($dayPrices)>100) { // $this->_saveRuleProductPrices($dayPrices); // $dayPrices = array(); // } // } // $this->_saveRuleProductPrices($dayPrices); // $write->commit(); } catch (Exception $e) { $write->rollback(); throw $e; } $productCondition = AO::getModel('catalog/product_condition')->setTable($this->getTable('catalogrule/affected_product'))->setPkFieldName('product_id'); AO::dispatchEvent('catalogrule_after_apply', array('product' => $product, 'product_condition' => $productCondition)); $write->delete($this->getTable('catalogrule/affected_product')); return $this; }
/** * Logout customer * * @return Mage_Customer_Model_Session */ public function logout() { if ($this->isLoggedIn()) { AO::dispatchEvent('customer_logout', array('customer' => $this->getCustomer())); $this->setId(null); } return $this; }
public function sendAction() { if (!$this->_validateFormKey()) { return $this->_redirect('*/*/'); } $emails = explode(',', $this->getRequest()->getPost('emails')); $message = nl2br(htmlspecialchars((string) $this->getRequest()->getPost('message'))); $error = false; if (empty($emails)) { $error = $this->__('Email address can\'t be empty.'); } else { foreach ($emails as $index => $email) { $email = trim($email); if (!Zend_Validate::is($email, 'EmailAddress')) { $error = $this->__('You input not valid email address.'); break; } $emails[$index] = $email; } } if ($error) { AO::getSingleton('wishlist/session')->addError($error); AO::getSingleton('wishlist/session')->setSharingForm($this->getRequest()->getPost()); $this->_redirect('*/*/share'); return; } $translate = AO::getSingleton('core/translate'); /* @var $translate Mage_Core_Model_Translate */ $translate->setTranslateInline(false); try { $customer = AO::getSingleton('customer/session')->getCustomer(); $wishlist = $this->_getWishlist(); /*if share rss added rss feed to email template*/ if ($this->getRequest()->getParam('rss_url')) { $rss_url = $this->getLayout()->createBlock('wishlist/share_email_rss')->toHtml(); $message .= $rss_url; } $wishlistBlock = $this->getLayout()->createBlock('wishlist/share_email_items')->toHtml(); $emails = array_unique($emails); $emailModel = AO::getModel('core/email_template'); foreach ($emails as $email) { $emailModel->sendTransactional(AO::getStoreConfig('wishlist/email/email_template'), AO::getStoreConfig('wishlist/email/email_identity'), $email, null, array('customer' => $customer, 'salable' => $wishlist->isSalable() ? 'yes' : '', 'items' => &$wishlistBlock, 'addAllLink' => AO::getUrl('*/shared/allcart', array('code' => $wishlist->getSharingCode())), 'viewOnSiteLink' => AO::getUrl('*/shared/index', array('code' => $wishlist->getSharingCode())), 'message' => $message)); } $wishlist->setShared(1); $wishlist->save(); $translate->setTranslateInline(true); AO::dispatchEvent('wishlist_share', array('wishlist' => $wishlist)); AO::getSingleton('customer/session')->addSuccess($this->__('Your Wishlist was successfully shared')); $this->_redirect('*/*'); } catch (Exception $e) { $translate->setTranslateInline(true); AO::getSingleton('wishlist/session')->addError($e->getMessage()); AO::getSingleton('wishlist/session')->setSharingForm($this->getRequest()->getPost()); $this->_redirect('*/*/share'); } }
/** * This method is called before rendering HTML * * @return Mage_Adminhtml_Block_Widget_Form */ protected function _beforeToHtml() { $this->_prepareForm(); $this->_initFormValues(); AO::dispatchEvent('adminhtml_widget_form_before_tohtml', array('form' => $this->getForm(), 'layout' => $this->getLayout())); return parent::_beforeToHtml(); }
public function shippingPostAction() { $shippingMethods = $this->getRequest()->getPost('shipping_method'); try { AO::dispatchEvent('checkout_controller_multishipping_shipping_post', array('request' => $this->getRequest(), 'quote' => $this->_getCheckout()->getQuote())); $this->_getCheckout()->setShippingMethods($shippingMethods); $this->_getState()->setActiveStep(Mage_Checkout_Model_Type_Multishipping_State::STEP_BILLING); $this->_getState()->setCompleteStep(Mage_Checkout_Model_Type_Multishipping_State::STEP_SHIPPING); $this->_redirect('*/*/billing'); } catch (Exception $e) { AO::getSingleton('checkout/session')->addError($e->getMessage()); $this->_redirect('*/*/shipping'); } }
/** * Set product visibility filter for enabled products * * @param array $visibility * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ public function setVisibility($visibility) { if ($this->_categoryIndexJoined) { $this->getSelect()->where('cat_index.visibility IN (?)', $visibility); } else { $condition = $this->getConnection()->quoteInto('enabled_index.visibility IN (?)', $visibility); $storeCondition = $this->getConnection()->quoteInto('enabled_index.store_id=?', $this->getStoreId()); $this->getSelect()->join(array('enabled_index' => $this->getTable('catalog/product_enabled_index')), 'enabled_index.product_id=e.entity_id AND ' . $storeCondition . ' AND ' . $condition, array()); } AO::dispatchEvent('catalog_product_collection_set_visibility_after', array('collection' => $this)); return $this; }
/** * Load nodes by parent id * * @param integer $parentId * @param integer $recursionLevel * @param integer $storeId * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat */ protected function _loadNodes($parentNode = null, $recursionLevel = 0, $storeId = 0) { $_conn = $this->_getReadAdapter(); $startLevel = 1; $parentPath = ''; if ($parentNode instanceof Mage_Catalog_Model_Category) { $parentPath = $parentNode->getPath(); $startLevel = $parentNode->getLevel(); } elseif (is_numeric($parentNode)) { $selectParent = $_conn->select()->from($this->getMainStoreTable())->where('entity_id = ?', $parentNode)->where('store_id = ?', '0'); if ($parentNode = $_conn->fetchRow($selectParent)) { $parentPath = $parentNode['path']; $startLevel = $parentNode['level']; } } $select = $_conn->select()->from(array('main_table' => $this->getMainStoreTable($storeId)), array('main_table.entity_id', 'main_table.name', 'main_table.path', 'main_table.is_active', 'main_table.is_anchor'))->joinLeft(array('url_rewrite' => $this->getTable('core/url_rewrite')), 'url_rewrite.category_id=main_table.entity_id AND url_rewrite.is_system=1 AND url_rewrite.product_id IS NULL AND url_rewrite.store_id="' . $storeId . '" AND url_rewrite.id_path LIKE "category/%"', array('request_path' => 'url_rewrite.request_path'))->where('main_table.is_active = ?', '1')->order('main_table.position', 'ASC'); if ($parentPath) { $select->where($_conn->quoteInto("main_table.path like ?", "{$parentPath}/%")); } if ($recursionLevel != 0) { $select->where("main_table.level <= ?", $startLevel + $recursionLevel); } $arrNodes = $_conn->fetchAll($select); $nodes = array(); foreach ($arrNodes as $node) { $node['id'] = $node['entity_id']; $nodes[$node['id']] = AO::getModel('catalog/category')->setData($node); } AO::dispatchEvent('catalog_category_flat_load_nodes_after', array('nodes' => $nodes)); return $nodes; }
public function getJsonConfig() { $config = array(); $_request = AO::getSingleton('tax/calculation')->getRateRequest(false, false, false); $_request->setProductClassId($this->getProduct()->getTaxClassId()); $defaultTax = AO::getSingleton('tax/calculation')->getRate($_request); $_request = AO::getSingleton('tax/calculation')->getRateRequest(); $_request->setProductClassId($this->getProduct()->getTaxClassId()); $currentTax = AO::getSingleton('tax/calculation')->getRate($_request); $_regularPrice = $this->getProduct()->getPrice(); $_finalPrice = $this->getProduct()->getFinalPrice(); $_priceInclTax = AO::helper('tax')->getPrice($this->getProduct(), $_finalPrice, true); $_priceExclTax = AO::helper('tax')->getPrice($this->getProduct(), $_finalPrice); $idSuffix = '__none__'; if ($this->hasOptions()) { $idSuffix = '_clone'; } $config = array('productId' => $this->getProduct()->getId(), 'priceFormat' => AO::app()->getLocale()->getJsPriceFormat(), 'includeTax' => AO::helper('tax')->priceIncludesTax() ? 'true' : 'false', 'showIncludeTax' => AO::helper('tax')->displayPriceIncludingTax(), 'showBothPrices' => AO::helper('tax')->displayBothPrices(), 'productPrice' => AO::helper('core')->currency($_finalPrice, false, false), 'productOldPrice' => AO::helper('core')->currency($_regularPrice, false, false), 'skipCalculate' => $_priceExclTax != $_priceInclTax ? 0 : 1, 'defaultTax' => $defaultTax, 'currentTax' => $currentTax, 'idSuffix' => $idSuffix, 'oldPlusDisposition' => 0, 'plusDisposition' => 0, 'oldMinusDisposition' => 0, 'minusDisposition' => 0); $responseObject = new Varien_Object(); AO::dispatchEvent('catalog_product_view_config', array('response_object' => $responseObject)); if (is_array($responseObject->getAdditionalOptions())) { foreach ($responseObject->getAdditionalOptions() as $option => $value) { $config[$option] = $value; } } return Zend_Json::encode($config); }
/** * Save customer action */ public function saveAction() { if ($data = $this->getRequest()->getPost()) { $redirectBack = $this->getRequest()->getParam('back', false); $this->_initCustomer('customer_id'); $customer = AO::registry('current_customer'); // Prepare customer saving data if (isset($data['account'])) { $customer->addData($data['account']); } if (isset($data['address'])) { // unset template data if (isset($data['address']['_template_'])) { unset($data['address']['_template_']); } foreach ($data['address'] as $index => $addressData) { $address = AO::getModel('customer/address'); $address->setData($addressData); if ($addressId = (int) $index) { $address->setId($addressId); } /** * We need set post_index for detect default addresses */ $address->setPostIndex($index); $customer->addAddress($address); } } if (isset($data['subscription'])) { $customer->setIsSubscribed(true); } else { $customer->setIsSubscribed(false); } $isNewCustomer = !$customer->getId(); try { if ($customer->getPassword() == 'auto') { $customer->setPassword($customer->generatePassword()); } // force new customer active if ($isNewCustomer) { $customer->setForceConfirmed(true); } $customer->save(); // send welcome email if ($customer->getWebsiteId() && $customer->hasData('sendemail')) { if ($isNewCustomer) { $customer->sendNewAccountEmail(); } elseif (!$customer->getConfirmation()) { $customer->sendNewAccountEmail('confirmed'); } } // TODO? Send confirmation link, if deactivating account if ($newPassword = $customer->getNewPassword()) { if ($newPassword == 'auto') { $newPassword = $customer->generatePassword(); } $customer->changePassword($newPassword); $customer->sendPasswordReminderEmail(); } AO::getSingleton('adminhtml/session')->addSuccess(AO::helper('adminhtml')->__('Customer was successfully saved')); AO::dispatchEvent('adminhtml_customer_save_after', array('customer' => $customer)); if ($redirectBack) { $this->_redirect('*/*/edit', array('id' => $customer->getId(), '_current' => true)); return; } } catch (Exception $e) { AO::getSingleton('adminhtml/session')->addError($e->getMessage()); AO::getSingleton('adminhtml/session')->setCustomerData($data); $this->getResponse()->setRedirect($this->getUrl('*/customer/edit', array('id' => $customer->getId()))); return; } } $this->getResponse()->setRedirect($this->getUrl('*/customer')); }
/** * Initialize creation data from existing order Item * * @param Mage_Sales_Model_Order_Item $orderItem * @return Mage_Sales_Model_Quote_Item | string */ public function initFromOrderItem(Mage_Sales_Model_Order_Item $orderItem, $qty = 1) { if (!$orderItem->getId()) { return $this; } $product = AO::getModel('catalog/product')->setStoreId($this->getSession()->getStoreId())->load($orderItem->getProductId()); if ($product->getId()) { $info = $orderItem->getProductOptionByCode('info_buyRequest'); $info = new Varien_Object($info); $product->setSkipCheckRequiredOption(true); $item = $this->getQuote()->addProduct($product, $info); if (is_string($item)) { return $item; } $item->setQty($qty); if ($additionalOptions = $orderItem->getProductOptionByCode('additional_options')) { $item->addOption(new Varien_Object(array('product' => $item->getProduct(), 'code' => 'additional_options', 'value' => serialize($additionalOptions)))); } AO::dispatchEvent('sales_convert_order_item_to_quote_item', array('order_item' => $orderItem, 'quote_item' => $item)); } return $item; }