/** * @test * @loadFixture questions */ public function deleteProductQuestionsForProduct() { $observer = new Varien_Object(); $event = new Varien_Object(); $store = Mage::getModel('core/store'); $product = Mage::getModel('catalog/product'); $product->setId(12); $product->setStore($store); $event->setProduct($product); $observer->setEvent($event); $this->assertEquals(2, $this->_data->deleteProductQuestionsForProduct($observer)); }
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())); }
/** * event after a customer group change */ public function customerGroupChangeListener($observer) { Mage::log('======go in customerGroupChangeListener', null, 'sp.log', true); try { $customer = $observer->getCustomer(); $orderCollection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id', array('eq' => array($customer->getId()))); if (count($orderCollection) > 0) { foreach ($orderCollection as $order) { foreach ($order->getAllItems() as $item) { $event = new Varien_Object(); $event->setItem($item); $arg_observer = new Varien_Object(); $arg_observer->setEvent($event); $this->savePinOrderItem($arg_observer); } } } } catch (Exception $e) { } Mage::log('======go out customerGroupChangeListener', null, 'sp.log', true); }