Beispiel #1
0
 /**
  * Process gift wrapping options on checkout proccess
  *
  * @param Varien_Object $observer
  * @return Enterprise_GiftWrapping_Model_Observer
  */
 public function checkoutProcessWrappingInfo($observer)
 {
     $request = $observer->getEvent()->getRequest();
     $giftWrappingInfo = $request->getParam('giftwrapping');
     if (is_array($giftWrappingInfo)) {
         $quote = $observer->getEvent()->getQuote();
         $giftOptionsInfo = $request->getParam('giftoptions');
         foreach ($giftWrappingInfo as $entityId => $data) {
             $info = array();
             if (!is_array($giftOptionsInfo) || empty($giftOptionsInfo[$entityId]['type'])) {
                 continue;
             }
             switch ($giftOptionsInfo[$entityId]['type']) {
                 case 'quote':
                     $entity = $quote;
                     $this->_saveOrderInfo($entity, $data);
                     break;
                 case 'quote_item':
                     $entity = $quote->getItemById($entityId);
                     $this->_saveItemInfo($entity, $data);
                     break;
                 case 'quote_address':
                     $entity = $quote->getAddressById($entityId);
                     $this->_saveOrderInfo($entity, $data);
                     break;
                 case 'quote_address_item':
                     $entity = $quote->getAddressById($giftOptionsInfo[$entityId]['address'])->getItemById($entityId);
                     $this->_saveItemInfo($entity, $data);
                     break;
             }
         }
     }
     return $this;
 }
Beispiel #2
0
 /**
  * If the quote has a delivery note then lets save that note and 
  * assign the id to the order
  * 
  * @param Varien_Object $observer
  * @return Dh_Deliverynote_Model_Observer
  */
 public function salesEventConvertQuoteToOrder($observer)
 {
     if ($note = $observer->getEvent()->getQuote()->getDeliveryNote()) {
         $deliveryNote = Mage::getModel('deliverynote/note')->setNote($note)->save();
         $observer->getEvent()->getOrder()->setDeliveryNoteId($deliveryNote->getDeliveryNoteId());
     }
     return $this;
 }
Beispiel #3
0
 /**
  * set accessories for save
  * @access public
  * @param Varien_Object $observer
  * @return Anais_Accessories_Model_Observer
  * @author Marius Strajeru <*****@*****.**>
  */
 public function beforeProductSave($observer)
 {
     $product = $observer->getEvent()->getProduct();
     $links = $observer->getEvent()->getRequest()->getPost('links');
     if (isset($links['accessories']) && !$product->getAccessoriesReadonly()) {
         $product->setAccessoriesLinkData(Mage::helper('adminhtml/js')->decodeGridSerializedInput($links['accessories']));
     }
     return $this;
 }
Beispiel #4
0
 /**
  * Convert specific attributes from Quote Payment to Order Payment
  *
  * @param Varien_Object $observer
  * @return Mage_Ideal_Model_Observer
  */
 public function convertPayment($observer)
 {
     $orderPayment = $observer->getEvent()->getOrderPayment();
     $quotePayment = $observer->getEvent()->getQuotePayment();
     $orderPayment->setIdealIssuerId($quotePayment->getIdealIssuerId());
     if ($quotePayment->getIdealIssuerId()) {
         $issuerList = unserialize($quotePayment->getIdealIssuerList());
         if (isset($issuerList[$quotePayment->getIdealIssuerId()])) {
             $orderPayment->setIdealIssuerTitle($issuerList[$quotePayment->getIdealIssuerId()]);
         }
     }
     return $this;
 }
 /**
  * Delete product item from Google Content
  *
  * @param Varien_Object $observer
  * @return BlueVisionTec_GoogleShoppingApi_Model_Observer
  */
 public function deleteProductItem($observer)
 {
     $product = $observer->getEvent()->getProduct();
     $items = $this->_getItemsCollection($product);
     Mage::getModel('googleshoppingapi/massOperations')->deleteItems($items);
     return $this;
 }
Beispiel #6
0
 /**
  * Runs before the customer behavior rule is saved to check the evlike settings.
  * @param Varien_Object $o
  */
 public function checkFacebookSettings($o)
 {
     $event = $o->getEvent();
     $this->setRequest($o->getControllerAction()->getRequest());
     $this->setResponse($o->getControllerAction()->getResponse());
     $post_data = $this->getRequest()->getPost();
     if (empty($post_data)) {
         return $this;
     }
     if ($post_data['points_conditions'] != TBT_Rewardssocial_Model_Facebook_Like_Special_Config::ACTION_CODE) {
         return $this;
     }
     $rewards_wiki_url = "https://sweettoothrewards.com/wiki/index.php/Sweet_Tooth_Facebook";
     if (!Mage::helper('rewardssocial/facebook_evlike')->isEvlikeEnabled()) {
         $msg = Mage::helper('rewardssocial')->__("The Facebook Like Module by Retail Evolved has not been installed or is disabled. It is required to reward customers for liking products on Facebook with Sweet Tooth. For more information, please [rewards_wiki_facebook_link]visit this help article[/rewards_wiki_facebook_link]. Your rule was still saved.");
         $msg = Mage::helper('rewardssocial')->getTextWithLinks($msg, 'rewards_wiki_facebook_link', $rewards_wiki_url, array('target' => '_wiki_sweet_tooth_facebook'));
         Mage::getSingleton('core/session')->addError($msg);
         return $this;
     }
     if (!Mage::helper('rewardssocial/facebook_evlike')->isEvlikeValidRewardsConfig()) {
         $evlike_config_url = Mage::helper('rewardssocial/facebook_evlike')->getConfigUrl();
         $msg = Mage::helper('rewardssocial')->__("The Facebook Like Module by Retail Evolved has not been configured properly.  Please visit the [evlike_config_link]Retail Evolved Facebook Like configuration[/evlike_config_link] section and change the Button Type to 'XFBML' or [rewards_wiki_facebook_link]visit this help article[/rewards_wiki_facebook_link]. Your rule was still saved.");
         $msg = Mage::helper('rewardssocial')->getTextWithLinks($msg, 'evlike_config_link', $evlike_config_url);
         $msg = Mage::helper('rewardssocial')->getTextWithLinks($msg, 'rewards_wiki_facebook_link', $rewards_wiki_url, array('target' => '_wiki_sweet_tooth_facebook'));
         Mage::getSingleton('core/session')->addError($msg);
         return $this;
     }
     return $this;
 }
 /**
  * Customer delete handler
  *
  * @param Varien_Object $observer
  * @return Mage_Newsletter_Model_Observer
  */
 public function customerDeleted($observer)
 {
     $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($observer->getEvent()->getCustomer()->getEmail());
     if ($subscriber->getId()) {
         $subscriber->delete();
     }
     return $this;
 }
Beispiel #8
0
 /**
  * Delete product item from Google Content
  *
  * @param Varien_Object $observer
  * @return Mage_GoogleShopping_Model_Observer
  */
 public function deleteProductItem($observer)
 {
     $product = $observer->getEvent()->getProduct();
     $items = $this->_getItemsCollection($product);
     try {
         Mage::getModel('Mage_GoogleShopping_Model_MassOperations')->deleteItems($items);
     } catch (Zend_Gdata_App_CaptchaRequiredException $e) {
         Mage::getSingleton('Mage_Adminhtml_Model_Session')->addError('Cannot delete Google Content Item. Google requires CAPTCHA.');
     }
     return $this;
 }
 /**
  * Delete product item from Google Content
  * @dispatch catalog_product_delete_before
  *
  * @param Varien_Object $observer
  *
  * @return Zookal_GShoppingV2_Model_Observer
  */
 public function deleteProductItem($observer)
 {
     $product = $observer->getEvent()->getProduct();
     $items = $this->_getItemsCollection($product);
     try {
         Mage::getModel('gshoppingv2/massOperations')->deleteItems($items);
     } catch (Exception $e) {
         Mage::getSingleton('adminhtml/session')->addError('Cannot delete Google Content Item. Google requires CAPTCHA.');
     }
     return $this;
 }
 /**
  * Set status of link
  *
  * @param Varien_Object $observer
  * @return Mage_Downloadable_Model_Observer
  */
 public function setLinkStatus($observer)
 {
     $order = $observer->getEvent()->getOrder();
     if (!$order->getId()) {
         //order not saved in the database
         return $this;
     }
     /* @var $order Mage_Sales_Model_Order */
     $status = '';
     $orderItemsIds = array();
     $orderItemStatusToEnable = Mage::getStoreConfig(Mage_Downloadable_Model_Link_Purchased_Item::XML_PATH_ORDER_ITEM_STATUS, $order->getStoreId());
     if ($order->getState() == Mage_Sales_Model_Order::STATE_HOLDED) {
         $status = Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING;
     } elseif ($order->isCanceled() || $order->getState() == Mage_Sales_Model_Order::STATE_CLOSED) {
         $status = Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_EXPIRED;
     } elseif ($order->getState() == Mage_Sales_Model_Order::STATE_PENDING_PAYMENT) {
         $status = Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING_PAYMENT;
     } elseif ($order->getState() == Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW) {
         $status = Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PAYMENT_REVIEW;
     } else {
         $availableStatuses = array($orderItemStatusToEnable, Mage_Sales_Model_Order_Item::STATUS_INVOICED);
         foreach ($order->getAllItems() as $item) {
             if ($item->getProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE || $item->getRealProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) {
                 if (in_array($item->getStatusId(), $availableStatuses)) {
                     $orderItemsIds[] = $item->getId();
                 }
             }
         }
         if ($orderItemsIds) {
             $status = Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_AVAILABLE;
         }
     }
     if (!$orderItemsIds && $status) {
         foreach ($order->getAllItems() as $item) {
             if ($item->getProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE || $item->getRealProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) {
                 $orderItemsIds[] = $item->getId();
             }
         }
     }
     if ($orderItemsIds) {
         $linkPurchased = Mage::getResourceModel('downloadable/link_purchased_item_collection')->addFieldToFilter('order_item_id', array('in' => $orderItemsIds));
         foreach ($linkPurchased as $link) {
             if ($link->getStatus() != Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_EXPIRED && $link->getStatus() != ICC_Ecodes_Helper_Downloadable::LINK_STATUS_REFUNDED) {
                 $link->setStatus($status)->save();
             }
         }
     }
     return $this;
 }
Beispiel #11
0
 /**
  * Clear the ESI block cache for a specific client
  *
  * Events:
  *     the events are applied dynamically according to what events are set
  *     for the various blocks' esi policies
  *
  * @param  Varien_Object $eventObject
  * @return null
  */
 public function banClientEsiCache($eventObject)
 {
     $eventName = $eventObject->getEvent()->getName();
     if (Mage::helper('turpentine/esi')->getEsiEnabled() && !in_array($eventName, $this->_esiClearFlag)) {
         $sessionId = Mage::app()->getRequest()->getCookie('frontend');
         if ($sessionId) {
             $result = $this->_getVarnishAdmin()->flushExpression('obj.http.X-Varnish-Session', '==', $sessionId, '&&', 'obj.http.X-Turpentine-Flush-Events', '~', $eventName);
             Mage::dispatchEvent('turpentine_ban_client_esi_cache', $result);
             if ($this->_checkResult($result)) {
                 Mage::helper('turpentine/debug')->logDebug('Cleared ESI cache for client (%s) on event: %s', $sessionId, $eventName);
             } else {
                 Mage::helper('turpentine/debug')->logWarn('Failed to clear Varnish ESI cache for client: %s', $sessionId);
             }
         }
         $this->_esiClearFlag[] = $eventName;
     }
 }
    /**
     * Run script
     *
     */
    public function run()
    {
        if($this->getArg('item') && ctype_digit($this->getArg('item'))) {
            echo "Loading sales order item " . $this->getArg('item') . '...' . PHP_EOL;
            $item = Mage::getModel('sales/order_item')->load($this->getArg('item'));
            if($item->getId() == $this->getArg('item')) {

                // Check if link already exists.  If yes, just return
                if(Mage::getModel('downloadable/link_purchased')->load($item->getId(), 'order_item_id')->getId()) {
                    echo "Link already exists for this item." . PHP_EOL;
                    return;
                }

                // Save downloadable link for order item
                $param = new Varien_Object( array(
                    'event' => new Varien_Object(array(
                            'item' => $item
                            )
                        )
                    ));

                if($param->getEvent()->getItem()->getId()) {
                    echo "Saving link..." . PHP_EOL;

                    Mage::getModel('downloadable/observer')
                        ->saveDownloadableOrderItem($param);

                    echo "Done. " . PHP_EOL . PHP_EOL;
                    echo "If this operation was unsuccessful, please check the order item id product_options. If the serialized links array is empty, then first fix it and try again. ". PHP_EOL;
                    echo "For example, if the product option has ...:5:\"links\";a:0:{}..., update with the link id such as ...:5:\"links\";a:1:{i:0;s:4:\"7647\";}..." . PHP_EOL;
                    echo "Then re-run this script. " . PHP_EOL;
                }
            }
            else {
                echo "Sales order item not found";
            }
        }
        else {
            echo $this->usageHelp();
        }


    }
Beispiel #13
0
 /**
  * Delete product item from Google Base
  *
  * @param Varien_Object $observer
  * @return Mage_GoogleBase_Model_Observer
  */
 public function deleteProductItem($observer)
 {
     try {
         $product = $observer->getEvent()->getProduct();
         if (Mage::getStoreConfigFlag('google/googlebase/observed', $product->getStoreId())) {
             $collection = Mage::getResourceModel('googlebase/item_collection')->addProductFilterId($product->getId())->load();
             foreach ($collection as $item) {
                 $item->deleteItem()->delete();
             }
         }
     } catch (Exception $e) {
         if (Mage::app()->getStore()->isAdmin()) {
             Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('googlebase')->__("Cannot update Google Base Item for Store '%s'", Mage::app()->getStore($item->getStoreId())->getName()));
         } else {
             throw $e;
         }
     }
     return $this;
 }
Beispiel #14
0
 /**
  * Copy quote custom option files to order custom option files
  *
  * @param Varien_Object $observer
  * @return Mage_Catalog_Model_Product_Option_Observer
  */
 public function copyQuoteFilesToOrderFiles($observer)
 {
     /* @var $quoteItem Mage_Sales_Model_Quote_Item */
     $quoteItem = $observer->getEvent()->getItem();
     if (is_array($quoteItem->getOptions())) {
         foreach ($quoteItem->getOptions() as $itemOption) {
             $code = explode('_', $itemOption->getCode());
             if (isset($code[1]) && is_numeric($code[1]) && ($option = $quoteItem->getProduct()->getOptionById($code[1]))) {
                 if ($option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_FILE) {
                     /* @var $_option Mage_Catalog_Model_Product_Option */
                     try {
                         $group = $option->groupFactory($option->getType())->setQuoteItemOption($itemOption)->copyQuoteToOrder();
                     } catch (Exception $e) {
                         continue;
                     }
                 }
             }
         }
     }
     return $this;
 }
 private function _OSCSaveBilling()
 {
     $helper = Mage::helper('onestepcheckout/checkout');
     $billing_data = $this->getRequest()->getPost('billing', array());
     $shipping_data = $this->getRequest()->getPost('shipping', array());
     $customerAddressId = $this->getRequest()->getPost('billing_address_id', false);
     $shippingAddressId = $this->getRequest()->getPost('shipping_address_id', false);
     $billing_data = $helper->load_exclude_data($billing_data);
     $shipping_data = $helper->load_exclude_data($shipping_data);
     if (!Mage::helper('customer')->isLoggedIn()) {
         $emailExists = Mage::helper('sagepaysuite')->existsCustomerForEmail($billing_data['email']);
         $regWithoutPassword = (int) Mage::getStoreConfig('onestepcheckout/registration/registration_order_without_password');
         if (1 === $regWithoutPassword && $emailExists) {
             // Place order on the emails account without the password
             $customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($billing_data['email']);
             Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer);
         } else {
             $registration_mode = Mage::getStoreConfig('onestepcheckout/registration/registration_mode');
             if ($registration_mode == 'auto_generate_account') {
                 // Modify billing data to contain password also
                 $password = Mage::helper('onestepcheckout/checkout')->generatePassword();
                 $billing_data['customer_password'] = $password;
                 $billing_data['confirm_password'] = $password;
                 $this->getOnepage()->getQuote()->getCustomer()->setData('password', $password);
                 $this->getOnepage()->getQuote()->setData('password_hash', Mage::getModel('customer/customer')->encryptPassword($password));
                 $this->getOnepage()->getQuote()->setData('customer_email', $billing_data['email']);
                 $this->getOnepage()->getQuote()->setData('customer_firstname', $billing_data['firstname']);
                 $this->getOnepage()->getQuote()->setData('customer_lastname', $billing_data['lastname']);
             }
             if ($registration_mode == 'require_registration' || $registration_mode == 'allow_guest') {
                 if (!empty($billing_data['customer_password']) && !empty($billing_data['confirm_password']) && $billing_data['customer_password'] == $billing_data['confirm_password']) {
                     $password = $billing_data['customer_password'];
                     $this->getOnepage()->getQuote()->setCheckoutMethod('register');
                     $this->getOnepage()->getQuote()->getCustomer()->setData('password', $password);
                     $this->getOnepage()->getQuote()->setData('customer_email', $billing_data['email']);
                     $this->getOnepage()->getQuote()->setData('customer_firstname', $billing_data['firstname']);
                     $this->getOnepage()->getQuote()->setData('customer_lastname', $billing_data['lastname']);
                     $this->getOnepage()->getQuote()->setData('password_hash', Mage::getModel('customer/customer')->encryptPassword($password));
                 }
             }
             if (!empty($billing_data['customer_password']) && !empty($billing_data['confirm_password'])) {
                 // Trick to allow saving of
                 Mage::getSingleton('checkout/type_onepage')->saveCheckoutMethod('register');
             }
         }
     }
     //Create Account hook
     if (Mage::helper('customer')->isLoggedIn() && $helper->differentShippingAvailable()) {
         if (!empty($customerAddressId)) {
             $billingAddress = Mage::getModel('customer/address')->load($customerAddressId);
             if (is_object($billingAddress) && $billingAddress->getCustomerId() == Mage::helper('customer')->getCustomer()->getId()) {
                 $billing_data = array_merge($billing_data, $billingAddress->getData());
             }
         }
         if (!empty($shippingAddressId)) {
             $shippingAddress = Mage::getModel('customer/address')->load($shippingAddressId);
             if (is_object($shippingAddress) && $shippingAddress->getCustomerId() == Mage::helper('customer')->getCustomer()->getId()) {
                 $shipping_data = array_merge($shipping_data, $shippingAddress->getData());
             }
         }
     }
     if (!empty($billing_data['use_for_shipping'])) {
         $shipping_data = $billing_data;
     }
     $this->getOnepage()->getQuote()->getBillingAddress()->addData($billing_data)->implodeStreetAddress()->setCollectShippingRates(true);
     $paymentMethod = $this->getRequest()->getPost('payment_method', false);
     $selectedMethod = $this->getOnepage()->getQuote()->getPayment()->getMethod();
     $store = $this->getOnepage()->getQuote() ? $this->getOnepage()->getQuote()->getStoreId() : null;
     $methods = $helper->getActiveStoreMethods($store, $this->getOnepage()->getQuote());
     if ($paymentMethod && !empty($methods) && !in_array($paymentMethod, $methods)) {
         $paymentMethod = false;
     }
     if (!$paymentMethod && $selectedMethod && in_array($selectedMethod, $methods)) {
         $paymentMethod = $selectedMethod;
     }
     if ($this->getOnepage()->getQuote()->isVirtual()) {
         $this->getOnepage()->getQuote()->getBillingAddress()->setPaymentMethod(!empty($paymentMethod) ? $paymentMethod : null);
     } else {
         $this->getOnepage()->getQuote()->getShippingAddress()->setPaymentMethod(!empty($paymentMethod) ? $paymentMethod : null);
     }
     try {
         if ($paymentMethod) {
             $this->getOnepage()->getQuote()->getPayment()->getMethodInstance();
         }
     } catch (Exception $e) {
     }
     //Breaks totals
     //$result = $this->getOnepage()->saveBilling($billing_data, $customerAddressId);
     if ($helper->differentShippingAvailable()) {
         if (empty($billing_data['use_for_shipping'])) {
             $shipping_result = $helper->saveShipping($shipping_data, $shippingAddressId);
         } else {
             $shipping_result = $helper->saveShipping($billing_data, $customerAddressId);
         }
     }
     $shipping_method = $this->getRequest()->getPost('shipping_method', false);
     if (!empty($shipping_method)) {
         $helper->saveShippingMethod($shipping_method);
     }
     //Commented, it breaks totals
     //$this->getOnepage()->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
     $requestParams = $this->getRequest()->getParams();
     if (array_key_exists('onestepcheckout_comments', $requestParams) && !empty($requestParams['onestepcheckout_comments'])) {
         $this->getSageSuiteSession()->setOscOrderComments($requestParams['onestepcheckout_comments']);
     }
     if (Mage::getStoreConfig('onestepcheckout/feedback/enable_feedback')) {
         $feedbackValues = unserialize(Mage::getStoreConfig('onestepcheckout/feedback/feedback_values'));
         $feedbackValue = $this->getRequest()->getPost('onestepcheckout-feedback');
         $feedbackValueFreetext = $this->getRequest()->getPost('onestepcheckout-feedback-freetext');
         if (!empty($feedbackValue)) {
             if ($feedbackValue != 'freetext') {
                 $feedbackValue = $feedbackValues[$feedbackValue]['value'];
             } else {
                 $feedbackValue = $feedbackValueFreetext;
             }
             $this->getSageSuiteSession()->setOscCustomerFeedback(Mage::helper('core')->escapeHtml($feedbackValue));
         }
     }
     //GiftMessage
     $event = new Varien_Object();
     $event->setEvent(new Varien_Object());
     $event->getEvent()->setRequest($this->getRequest());
     $event->getEvent()->setQuote($this->getOnepage()->getQuote());
     Mage::getModel('giftmessage/observer')->checkoutEventCreateGiftMessage($event);
     if (array_key_exists('subscribe_newsletter', $requestParams) && (int) $requestParams['subscribe_newsletter'] === 1) {
         $this->getSageSuiteSession()->setOscNewsletterEmail($this->getOnepage()->getQuote()->getBillingAddress()->getEmail());
     }
     //GiftCard
     Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array('request' => $this->getRequest(), 'quote' => $this->getOnepage()->getQuote()));
 }
Beispiel #16
0
 /**
  * Delete category scripts after deleting category
  *
  * @param   Varien_Object $observer
  * @return  Mage_Googleoptimizer_Model_Observer
  */
 public function deleteCategoryGoogleOptimizerScripts($observer)
 {
     $category = $observer->getEvent()->getCategory();
     $googleOptimizer = AO::getModel('googleoptimizer/code_category')->setEntity($category)->deleteScripts($category->getStoreId());
     return $this;
 }
Beispiel #17
0
 /**
  * Setting attribute tab block for bundle
  *
  * @param Varien_Object $observer
  * @return Mage_Bundle_Model_Observer
  */
 public function setAttributeTabBlock($observer)
 {
     $product = $observer->getEvent()->getProduct();
     if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
         Mage::helper('adminhtml/catalog')->setAttributeTabBlock('bundle/adminhtml_catalog_product_edit_tab_attributes');
     }
     return $this;
 }
Beispiel #18
0
 /**
  * Add Optimization tab to the Catalog Category edit page
  *
  * @param Varien_Object $observer
  * @return Mage_GoogleOptimizer_Model_Observer
  */
 public function addCategoryGoogleOptimizerTab($observer)
 {
     $tabs = $observer->getEvent()->getTabs();
     if (Mage::app()->getConfig()->getModuleConfig('Mage_GoogleOptimizer')->is('active', true) && Mage::helper('Mage_GoogleOptimizer_Helper_Data')->isOptimizerActive($tabs->getCategory()->getStoreId())) {
         $tabs->addTab('googleoptimizer', array('label' => Mage::helper('Mage_GoogleOptimizer_Helper_Data')->__('Category View Optimization'), 'content' => $tabs->getLayout()->createBlock('Mage_GoogleOptimizer_Block_Adminhtml_Catalog_Category_Edit_Tab_Googleoptimizer')->toHtml()));
     }
     return $this;
 }
Beispiel #19
0
 /**
  * This gets triggered AFTER totals are collected so we can make sure nothing went below 0
  * Sometimes rounding brings us bellow 0.0000000000001 or we get "-0.00".
  * @param Varien_Object $o
  */
 public function cleanup($o)
 {
     $quote = $o->getEvent()->getQuote();
     //@nelkaake -a 11/03/11: Reset the counting discount field
     foreach ($quote->getAllAddresses() as $address) {
         if ($address->getGrandTotal() <= -0) {
             $address->setGrandTotal(0);
         }
     }
     return $this;
 }
Beispiel #20
0
 /**
  * Set giftmessage available default value to product
  * on catalog products collection load
  *
  * @param Varien_Object $observer
  * @return Mage_GiftMessage_Model_Observer
  */
 public function catalogEventProductCollectionAfterLoad($observer)
 {
     $collection = $observer->getEvent()->getCollection();
     foreach ($collection as $item) {
         if ($item->getGiftMessageAvailable() === null) {
             $item->setGiftMessageAvailable(2);
         }
     }
     return $this;
 }
Beispiel #21
0
 /**
  * Log an occurance of a specific event
  *
  * @param  Varien_Object $eventObject
  * @return null
  */
 public function logEvent($eventObject)
 {
     Mage::helper('turpentine/debug')->log('EVENT: %s', $eventObject->getEvent()->getName());
 }
Beispiel #22
0
 /**
  * Set status of link
  *
  * @param Varien_Object $observer        	
  * @return Mage_Downloadable_Model_Observer
  */
 public function setPinStatus($observer)
 {
     $order = $observer->getEvent()->getOrder();
     if (!$order->getId()) {
         // order not saved in the database
         return $this;
     }
     /* @var $order Mage_Sales_Model_Order */
     $status = '';
     $pinStatuses = array('pending' => HN_Pin_Model_Pin::STATUS_PENDING, 'expired' => HN_Pin_Model_Pin::STATUS_EXPIRED, 'avail' => HN_Pin_Model_Pin::STATUS_AVAILABLE, 'payment_pending' => HN_Pin_Model_Pin::STATUS_PENDING_PAYMENT, 'payment_review' => HN_Pin_Model_Pin::STATUS_PAYMENT_REVIEW, 'sold_out' => HN_Pin_Model_Pin::STATUS_SOLD_OUT);
     $pinItemsStatuses = array();
     if ($order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE) {
         foreach ($order->getAllItems() as $item) {
             if ($item->getProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE || $item->getRealProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) {
                 if (in_array($item->getStatusId(), $expiredStatuses)) {
                     $downloadableItemsStatuses[$item->getId()] = $linkStatuses['expired'];
                 } else {
                     $downloadableItemsStatuses[$item->getId()] = $linkStatuses['avail'];
                 }
             }
         }
         return $this;
     }
 }
Beispiel #23
0
 /**
  * Set gift messages to order from quote address
  *
  * @param Varien_Object $observer
  * @return Mage_GiftMessage_Model_Observer
  */
 public function salesEventConvertQuoteToOrder($observer)
 {
     $observer->getEvent()->getOrder()->setGiftMessageId($observer->getEvent()->getQuote()->getGiftMessageId());
     return $this;
 }
Beispiel #24
0
 /**
  * Clean product index when product deleted or marked as unsearchable/invisible
  *
  * @param Varien_Object $observer
  * @return Mage_CatalogSearch_Model_Fulltext_Observer
  */
 public function cleanProductIndex($observer)
 {
     $product = $observer->getEvent()->getProduct();
     Mage::getModel('catalogsearch/fulltext')->cleanIndex(null, $product->getId())->resetSearchResults();
     return $this;
 }
Beispiel #25
0
 /**
  * Set status of link
  *
  * @param Varien_Object $observer
  * @return Mage_Downloadable_Model_Observer
  */
 public function setLinkStatus($observer)
 {
     $order = $observer->getEvent()->getOrder();
     /* @var $order Mage_Sales_Model_Order */
     $status = '';
     $orderItemsIds = array();
     $orderItemStatusToEnable = Mage::getStoreConfig(Mage_Downloadable_Model_Link_Purchased_Item::XML_PATH_ORDER_ITEM_STATUS);
     if ($order->getState() == Mage_Sales_Model_Order::STATE_HOLDED) {
         $status = Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING;
     } elseif ($order->getState() == Mage_Sales_Model_Order::STATE_CANCELED || $order->getState() == Mage_Sales_Model_Order::STATE_CLOSED) {
         $status = Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_EXPIRED;
     } elseif ($order->getState() == Mage_Sales_Model_Order::STATE_PENDING_PAYMENT) {
         $status = Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING_PAYMENT;
     } else {
         foreach ($order->getAllItems() as $item) {
             if ($item->getProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE || $item->getRealProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) {
                 if ($item->getStatusId() == $orderItemStatusToEnable) {
                     $orderItemsIds[] = $item->getId();
                 }
             }
         }
         if ($orderItemsIds) {
             $status = Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_AVAILABLE;
         }
     }
     if (!$orderItemsIds && $status) {
         foreach ($order->getAllItems() as $item) {
             if ($item->getProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE || $item->getRealProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) {
                 $orderItemsIds[] = $item->getId();
             }
         }
     }
     if ($orderItemsIds) {
         $linkPurchased = Mage::getResourceModel('downloadable/link_purchased_item_collection')->addFieldToFilter('order_item_id', array('in' => $orderItemsIds));
         foreach ($linkPurchased as $link) {
             if ($link->getStatus() != Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_EXPIRED) {
                 $link->setStatus($status)->save();
             }
         }
     }
     return $this;
 }
 /**
  * Reset validation data
  *
  * @param Varien_Object $observer
  * @return Mage_Centinel_Model_Observer
  */
 public function checkoutSubmitAllAfter($observer)
 {
     $method = false;
     if ($order = $observer->getEvent()->getOrder()) {
         $method = $order->getPayment()->getMethodInstance();
     } elseif ($orders = $observer->getEvent()->getOrders()) {
         if ($order = array_shift($orders)) {
             $method = $order->getPayment()->getMethodInstance();
         }
     }
     if ($method && $method->getIsCentinelValidationEnabled()) {
         $method->getCentinelValidator()->reset();
     }
     return $this;
 }
 public function output_Chinmay_redirect(Varien_Object $observer)
 {
     if (isset($_POST['payment']['method']) && $_POST['payment']['method'] == "Chinmay") {
         $controller = $observer->getEvent()->getData('controller_action');
         $result = Mage::helper('core')->jsonDecode($controller->getResponse()->getBody('default'), Zend_Json::TYPE_ARRAY);
         if (Mage::getStoreConfig('payment/Chinmay/inline') == '1') {
             $js = '<script>
                 document.getElementById("review-please-wait").style["display"] = "block";
                 if ($$("a.top-link-cart")) {
                     $$("a.top-link-cart")[0].href = "' . Mage::getUrl('Chinmay/redirect/cart', array('_secure' => true)) . '";
                 }
                 if ($$("p.f-left").length !== 0) {
                     $$("p.f-left")[0].style["display"] = "none";
                 }
                 function formSubmit() {
                     $("Chinmaysubmit").click();
                 }
                 var Chinmayhead = $$("head")[0];
                 var Chinmayscript = new Element("script", { type: "text/javascript", src: "https://www.2checkout.com/static/checkout/javascript/direct.min.js" });
                 Chinmayhead.appendChild(Chinmayscript);
                 var checkoutOrderBtn = $$("button.btn-checkout");
                 checkoutOrderBtn[0].removeAttribute("onclick");
                 checkoutOrderBtn[0].observe("click", formSubmit);
                 new PeriodicalExecuter(function(pe) {
                     if (typeof window["inline_2Checkout"] != "undefined")
                     {
                         formSubmit();
                         pe.stop();
                     }
                 }, 0.50);
             </script>';
         } else {
             $js = '<script>
                 document.getElementById("review-please-wait").style["display"] = "block";
                 if ($$("a.top-link-cart")) {
                     $$("a.top-link-cart")[0].href = "' . Mage::getUrl('Chinmay/redirect/cart', array('_secure' => true)) . '";
                 }
                 if ($$("p.f-left").length !== 0) {
                     $$("p.f-left")[0].style["display"] = "none";
                 }
                 function formSubmit() {
                     $("Chinmaysubmit").click();
                 }
                 var checkoutOrderBtn = $$("button.btn-checkout");
                 checkoutOrderBtn[0].removeAttribute("onclick");
                 checkoutOrderBtn[0].observe("click", formSubmit);
                 formSubmit();
             </script>';
         }
         if (empty($result['error'])) {
             $controller->loadLayout('checkout_onepage_review');
             $html = $controller->getLayout()->createBlock('Chinmay/redirect')->toHtml();
             $html .= $js;
             $result['update_section'] = array('name' => 'Chinmayiframe', 'html' => $html);
             $result['redirect'] = false;
             $result['success'] = false;
             $controller->getResponse()->clearHeader('Location');
             $controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
         }
     }
     return $this;
 }
Beispiel #28
0
 /**
  * Set status of link
  *
  * @param Varien_Object $observer
  * @return Mage_Downloadable_Model_Observer
  */
 public function setLinkStatus($observer)
 {
     $order = $observer->getEvent()->getOrder();
     if (!$order->getId()) {
         //order not saved in the database
         return $this;
     }
     /* @var $order Mage_Sales_Model_Order */
     $status = '';
     $linkStatuses = array('pending' => Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING, 'expired' => Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_EXPIRED, 'avail' => Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_AVAILABLE, 'payment_pending' => Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING_PAYMENT, 'payment_review' => Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PAYMENT_REVIEW);
     $downloadableItemsStatuses = array();
     $orderItemStatusToEnable = Mage::getStoreConfig(Mage_Downloadable_Model_Link_Purchased_Item::XML_PATH_ORDER_ITEM_STATUS, $order->getStoreId());
     if ($order->getState() == Mage_Sales_Model_Order::STATE_HOLDED) {
         $status = $linkStatuses['pending'];
     } elseif ($order->isCanceled() || $order->getState() == Mage_Sales_Model_Order::STATE_CLOSED || $order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE) {
         $expiredStatuses = array(Mage_Sales_Model_Order_Item::STATUS_CANCELED, Mage_Sales_Model_Order_Item::STATUS_REFUNDED);
         foreach ($order->getAllItems() as $item) {
             if ($item->getProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE || $item->getRealProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) {
                 if (in_array($item->getStatusId(), $expiredStatuses)) {
                     $downloadableItemsStatuses[$item->getId()] = $linkStatuses['expired'];
                 } else {
                     $downloadableItemsStatuses[$item->getId()] = $linkStatuses['avail'];
                 }
             }
         }
     } elseif ($order->getState() == Mage_Sales_Model_Order::STATE_PENDING_PAYMENT) {
         $status = $linkStatuses['payment_pending'];
     } elseif ($order->getState() == Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW) {
         $status = $linkStatuses['payment_review'];
     } else {
         $availableStatuses = array($orderItemStatusToEnable, Mage_Sales_Model_Order_Item::STATUS_INVOICED);
         foreach ($order->getAllItems() as $item) {
             if ($item->getProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE || $item->getRealProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) {
                 if ($item->getStatusId() == Mage_Sales_Model_Order_Item::STATUS_BACKORDERED && $orderItemStatusToEnable == Mage_Sales_Model_Order_Item::STATUS_PENDING && !in_array(Mage_Sales_Model_Order_Item::STATUS_BACKORDERED, $availableStatuses, true)) {
                     $availableStatuses[] = Mage_Sales_Model_Order_Item::STATUS_BACKORDERED;
                 }
                 if (in_array($item->getStatusId(), $availableStatuses)) {
                     $downloadableItemsStatuses[$item->getId()] = $linkStatuses['avail'];
                 }
             }
         }
     }
     if (!$downloadableItemsStatuses && $status) {
         foreach ($order->getAllItems() as $item) {
             if ($item->getProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE || $item->getRealProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) {
                 $downloadableItemsStatuses[$item->getId()] = $status;
             }
         }
     }
     if ($downloadableItemsStatuses) {
         $linkPurchased = Mage::getResourceModel('downloadable/link_purchased_item_collection')->addFieldToFilter('order_item_id', array('in' => array_keys($downloadableItemsStatuses)));
         foreach ($linkPurchased as $link) {
             if ($link->getStatus() != $linkStatuses['expired'] && !empty($downloadableItemsStatuses[$link->getOrderItemId()])) {
                 $link->setStatus($downloadableItemsStatuses[$link->getOrderItemId()])->save();
             }
         }
     }
     return $this;
 }
Beispiel #29
0
 /**
  * Gets triggered on the 'checkout_cart_product_update_after' event to append points information
  * to a quote item upon being updated
  * @param Varien_Object $o
  */
 public function appendPointsQuoteAfterUpdate($o)
 {
     $event = $o->getEvent();
     if (!$event) {
         return $this;
     }
     $item = $event->getQuoteItem();
     $product = $event->getProduct();
     $request = Mage::app()->getRequest();
     if (!$request || !$product || !$item) {
         return $this;
     }
     if ($item->getParentItem()) {
         $item = $item->getParentItem();
     }
     $apply_rule_id = $request->getParam('redemption_rule');
     $apply_rule_uses = $request->getParam('redemption_uses');
     $qty = $request->getParam('qty');
     $previous_rule_id = $request->getParam('redemption_rule_prev');
     // if $apply_rule_id is empty but there was a previous rule applied, we're actually trying to clear that rule
     if (!$apply_rule_id && $previous_rule_id) {
         $apply_rule_id = $previous_rule_id;
         $apply_rule_uses = 0;
     }
     $this->_writePointsToQuote($product, $item, $apply_rule_id, $apply_rule_uses, $qty);
     return $this;
 }
Beispiel #30
0
 /**
  * Setting attribute tab block for bundle
  *
  * @param Varien_Object $observer
  * @return Mage_Bundle_Model_Observer
  */
 public function setAttributeTabBlock($observer)
 {
     $product = $observer->getEvent()->getProduct();
     if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
         Mage::helper('Mage_Adminhtml_Helper_Catalog')->setAttributeTabBlock('Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Attributes');
     }
     return $this;
 }