I created custom shipping method for magento. And this method needed only for orders created programmatically from others modules.
Question: How i can to hide this method from checkout form without disabling this method in store settings?
I assume the other modules will use your shipping method from admin context; so you could do something like this:
update your collectRates method like this:
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!Mage::app()->getStore()->isAdmin())) {
return false;
}
// rest of your code
This way, you should be able to have the shipping method active but only usable in admin context.
Related
I am trying to add a hook in my custom module but it is not fired after I add a customer both in prestashop backoffice or by using the webservice.
The hook name I am trying to register is "actionCustomerAccountAdd".
This is the relevant code of the module. Please could you help me? I am a PHP developer but it is the first time I develop in Prestashop side.
/**
* Don't forget to create update methods if needed:
* http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update
*/
public function install()
{
return parent::install()
&& $this->createRequiredDBTables()
&& $this->registerHook('actionCustomerAccountAdd');
}
I have this code to check in logs files or page but it is not fired:
public function hookActionCustomerAccountAdd($params)
{
$this->logger->info('Hook action customer account add fired');
echo 'hook fired';
die();
}
Thank you.
The thing is that hook actionCustomerAccountAdd is fired only on front-office, you will need to use actionObjectCustomerAddAfter, dynamic hook executed in classes/ObjectModel.php
I am building a custom module in prestashop and I need to execute something after payment accepted and after the emails have been sent. In mymodule.php I have the following hooks:
public function hookActionValidateOrder($params) {
$order = $params['order'];
$customer = $params['customer'];
$valuesToinsert="";
$attrValue=array();
etc...
}
Which is executed normally. I tried actionOrderStatusPostUpdate, actionPaymentConfirmation but none of these seems to be called. I dont know whether it is relevant but I am using opc module and the product is free of charge.
This hook is call when an order is placed after a client confirm his cart. The function that triggers this hook is validateOrder from PaymentModule class. It is call by payment modules when client click en confirm button in checkout. Every payment module should call this function in some moment. But, if you don't have a payment module in your specific process due to free product this hook could maybe be never called.
Anyway, you can subscribe to actionObjectOrderAddAfter hook or similar to get notified when a new order is placed:
public function hookActionObjectOrderAddAfter($params)
{
//$params['object'] contains specific object, in this case your Order object
}
If you need information about order status you could subscribe to hook actionOrderHistoryAddAfter too. Hook actionOrderStatusUpdate is only trigger inside changeIdOrderState function. If for some reason order status change with no call to this function you will miss notification.
Good luck
As you have mentioned in your question that the order you are trying is free, in this case any hook that is called on payment, will never call.
Hence the hooks (i.e. actionOrderStatusPostUpdate, actionPaymentConfirmation, hookActionObjectOrderAddAfter etc.) will never be called as they are called from the PaymentModule.php class and it is not called at all in case of a free order.
Unfortunately, there are no hooks that are called when a free order is placed. In case you want to take any action on a Free order then you can only do that by overriding the FreeOrder class or _checkFreeOrder() function in ParentOrderController.php
Old post, but wanted to drop a comment to help others. This function calls after an order is submitted and they get the confirmation page, whether a payment was submitted with it or not:
public function hookDisplayOrderConfirmation($params) { }
I want to programmatically set a default payment method (radio is checked) in woocommerce checkout page based on a condition using php (not jquery).
Lets say I have two payment methods:
'pay_method1' and 'pay_method2'
Most solutions suggest removing a method in order to select the other:
unset($gateways['pay_method1']) //auto selects pay_method2 naturally
But I don't want to remove the method. I only want to set a default when the checkout page loads / reloads, so the the user can still switch methods if needed.
I plan on having the following action in functions.php:
add_action("woocommerce_before_checkout_form", "custom_before_checkout_action");
function custom_before_checkout_action() {
if ($my_condition) {
//default to pay_method1 - how??
}
else {
//default to pay_method2 - how??
}
}
Is this possible to tell woocommerce which payment method should be checked this way?
You can see woocommerce template structure checkout folder have file payment-method.php. There are payment method $gateway object
have property $gateway->chosen to access true default checked payment gateway.
add_filter('woocommerce_available_payment_gateways', 'show_custom_payment_gateways');
function show_custom_payment_gateways( $available_gateways){
global $woocommerce;
$available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
if( $myconditon ){
$available_gateways['pay_method2']->chosen = true;
$available_gateways['pay_method1']->chosen = false // default to false unchecked.
}
}
I've installed a plugin that enables a custom shipping method into my store (calculates shipping method with my postal service).
It works with any product, except those with recurring profile enabled.
I found this link http://www.magentocommerce.com/knowledge-base/entry/working-with-recurring-profiles/Magento-Knowledge-Base-Working-with-Recurring-Profiles saying:
... For products with recurring profiles, the customer can only choose
between the fixed-price shipping methods (flat, table or free) when
checking out. ...
Why there is this rule? How can I make my custom shipping method work with recurring profile products?
I've tried these plugins and both doesn't work.
https://github.com/pedro-teixeira/correios
https://github.com/willstorm/correios
Which files should I look at to edit to solve this?
To solve this you need to basically change your shipping method class in order to add this:
class Namespace_Shipping_Model_Carrier_Customrate
extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface
{
protected $_code = 'my_customrate';
protected $_isFixed = true; // << THIS ONE
...
}
I have an extension for product registration that dispatches an event after the registration is saved. Another extension uses that event to generate a coupon for a virtual product if it is related to the registered product.
I need to get back data on the generated coupon to send to the user in an email along with the details of their product registration.
Is there a way to return data from the observer back to where the event is dispatched?
There is a trick available in Magento for your purpose. Since you can pass event data to the observers, like product or category model, it also possible to create a container from which you can get this data.
For instance such actions can be performed in dispatcher:
$couponContainer = new Varien_Object();
Mage::dispatchEvent('event_name', array('coupon_container' => $couponContainer));
if ($couponContainer->getCode()) {
// If some data was set by observer...
}
And an observer method can look like the following:
public function observerName(Varien_Event_Observer $observer)
{
$couponContainer = $observer->getEvent()->getCouponContainer();
$couponContainer->setCode('some_coupon_code');
}
Enjoy and have fun!
No, there's nothing built in to the system for doing this. The Magento convention is to create a stdClass or Varien_Object transport object.
Take a look at the block event code
#File: app/code/core/Mage/Core/Block/Abstract.php
...
if (self::$_transportObject === null)
{
self::$_transportObject = new Varien_Object;
}
self::$_transportObject->setHtml($html);
Mage::dispatchEvent('core_block_abstract_to_html_after',
array('block' => $this, 'transport' => self::$_transportObject));
$html = self::$_transportObject->getHtml();
...
Since self::$_transportObject is an object, and PHP objects behave in a reference like manner, any changes made to the transport object in an observer will be maintained. So, in the above example, if an observer developer said
$html = $observer->getTransport()-setHtml('<p>New Block HTML');
Back up in the system block code self::$_transportObject would contain the new HTML. Keep in mind that multiple observers will have a chance to change this value, and the order observers fire in Magento will be different for each configured system.
A second approach you could take is to use Magento's registry pattern. Register a variable before the dispatchEvent