How to remove delivery shipping step on prestashop 1.6.1? - prestashop

I'm new to prestashop and I'm having major trouble removing the delivery shipping step because I only sell virtual products. I am using prestashop 1.6.1.
I know I have to modify order-carrier.tpl file and have followed several posts here and there but couldn't get it done right.
Does any of you have any actual idea on how to do this ?

Bonjour, here is what i did
Override AdminOrderPreferencesController and add a boolean configuration field to toggle this functionnality
$this->fields_options = array(
[...]
'PS_ORDER_PROCESS_BYPASS_SHIPPING' => array(
'title' => $this->l('Bypass shipping step'),
'hint' => $this->l('Do not show shipping step in order process.'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool'
)
);
You can now find a toggle button in Backoffice under Preferences > Orders
Override OrderController and add an if in init() method to set the current step to payment step if the controller inits itself on delivery step
public function init()
{
global $orderTotal;
parent::init();
$this->step = (int)Tools::getValue('step');
// HERE IT IS
if((bool)Configuration::get('PS_ORDER_PROCESS_BYPASS_SHIPPING') && $this->step == self::STEP_DELIVERY){
$this->step = self::STEP_PAYMENT;
}
if (!$this->nbProducts) {
$this->step = -1;
}
Also bypass the CGV checking verification on payment step in initContent() method.
If you don't, CGV will never be checked, it will redirect you on delivery step, you will tell him that he is in fact on payment step, he will check for CGV again, he will do the same redirection ... and you are in an infinite loop
case OrderController::STEP_PAYMENT:
$cgv = Tools::getValue('cgv') || $this->context->cookie->check_cgv;
if (
!(bool)Configuration::get('PS_ORDER_PROCESS_BYPASS_SHIPPING') && // HERE IT IS
$is_advanced_payment_api === false && Configuration::get('PS_CONDITIONS')
&& (!Validate::isBool($cgv) || $cgv == false)
) {
Tools::redirect('index.php?controller=order&step=2');
}
Pass the configuration parameter to the view to modify display
$this->context->smarty->assign('bypass_shipping_step', (bool)Configuration::get('PS_ORDER_PROCESS_BYPASS_SHIPPING'));
And in your views, do you styling stuff with some if
In order-steps.tpl you can add an {if not $bypass_shipping_step}...{/if} around the fourth li to hide it, and do something like :
{if $bypass_shipping_step}
<style>
ul.step li{
width:25%;
}
</style>
{/if}
or import a dedicated stylesheet which would be cleaner.
Hope it helped.

In shopping-cart.tpl, remove call to order-carrier.tpl. If you are not using one pagecheckout, in orderController.php, you have to change all redirection to step 2 (shipping method choosing), to redirection step 3 Tools::redirect('index.php?controller=order&step=2'); to Tools::redirect('index.php?controller=order&step=3');

Related

WHMCS - Disable Module Buttons in Product Page

Ive written a provisioning module for WHMCS and attached it to a product but the module presents 6 buttons, Create, Suspend, Terminate, Change Package, and Change Password. I dont need these buttons as they make no sense for my module, instead I have some custom ones that do what I need, how do I remove these buttons from the product page?
Can't find anything on the WHMCS documentation to describe how to remove or even change the text of the buttons.
Did you check Custom Functions in the Provisioning Modules documentation?
To add client area buttons/functions:
function mymodule_ClientAreaCustomButtonArray() {
//Add or remove items as required
$buttonarray = array(
"Reboot Server" => "reboot",
"Custom Label" => "customlabel",
);
return $buttonarray;
}
//customlabel implementation
function mymodule_customlabel($params) {
# Code to perform customlabel action goes here...
if ($successful) {
$result = "success";
} else {
$result = "Error Message Goes Here...";
}
return $result;
}

Prestashop displayPaymentReturn hook url

I am new as Prestashop developer and I am trying to create a PaymentModule. I have got to show my payment method but I can not proceed with purchase because I do not know very well hot it works.
Does anyone know where I should redirect to run my hoodDisplayPaymentReturn method?
I will be very happy if someone explain me the complete navigation map to make a purchase.
Anyway, where can I find a relation between hooks and pages?
To develop a payment module you should use 2 main hooks: payment and paymentReturn.
In payment hook you must display your payment option with the specific information. Check bankwire module to see a working example.
In paymentReturn you should show the payment confirmation (or error) information.
When a user click on your payment option link (displayed in payment hook) you should do some validation and processing. After a payment is done (successfully or not) you must call to your module function validateOrder (this is a function of PaymentModule parent class of your module). After that you should be redirected to a controller that will execute paymentReturn hook.
That is the basic process. I strongly recommend you that check bankwire and other payment modules to understand better how to do your own payment module, because is not an easy task for beginner.
Good luck.
when I have a new module for the payment I rely on the simplest provided by PrestaShop: bankwire.
inside you can find 3 hooks.
HookPayment:
public function hookPayment($params)
{
if (!$this->active)
return;
if (!$this->checkCurrency($params['cart']))
return;
$this->smarty->assign(array(
'this_path' => $this->_path,
'this_path_bw' => $this->_path,
'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/'
));
return $this->display(__FILE__, 'payment.tpl');
}
hookDisplayPaymentEU:
public function hookDisplayPaymentEU($params)
{
if (!$this->active)
return;
if (!$this->checkCurrency($params['cart']))
return;
$payment_options = array(
'cta_text' => $this->l('Pay by Bank Wire'),
'logo' => Media::getMediaPath(_PS_MODULE_DIR_.$this->name.'/bankwire.jpg'),
'action' => $this->context->link->getModuleLink($this->name, 'validation', array(), true)
);
return $payment_options;
}
hookPaymentReturn:
public function hookPaymentReturn($params)
{
if (!$this->active)
return;
$state = $params['objOrder']->getCurrentState();
if (in_array($state, array(Configuration::get('PS_OS_BANKWIRE'), Configuration::get('PS_OS_OUTOFSTOCK'), Configuration::get('PS_OS_OUTOFSTOCK_UNPAID'))))
{
$this->smarty->assign(array(
'total_to_pay' => Tools::displayPrice($params['total_to_pay'], $params['currencyObj'], false),
'bankwireDetails' => Tools::nl2br($this->details),
'bankwireAddress' => Tools::nl2br($this->address),
'bankwireOwner' => $this->owner,
'status' => 'ok',
'id_order' => $params['objOrder']->id
));
if (isset($params['objOrder']->reference) && !empty($params['objOrder']->reference))
$this->smarty->assign('reference', $params['objOrder']->reference);
}
else
$this->smarty->assign('status', 'failed');
return $this->display(__FILE__, 'payment_return.tpl');
}

Prestashop BlockCategories doesn't add "selected" class on active links

I have this standard link in category-tree-branch.tpl:
<a href="{$node.link|escape:'html':'UTF-8'}"{if isset($currentCategoryId) && $node.id == $currentCategoryId} class="selected"{/if} title="{$node.desc|strip_tags|trim|escape:'html':'UTF-8'}">
{$node.name|escape:'html':'UTF-8'}
</a>
But my links do not have the selected class when active, which causes categories to be closed, hiding subcategories of current category, which ruins the UX completely.
Is there any other info I can give?
Any ideas?
I did fount the solution myself.
if ((Tools::getValue('id_product') || Tools::getValue('id_category')) && isset($this->context->cookie->last_visited_category) && $this->context->cookie->last_visited_category)
{
$category = new Category($this->context->cookie->last_visited_category, $this->context->language->id);
if (Validate::isLoadedObject($category))
$this->smarty->assign(array('currentCategory' => $category, 'currentCategoryId' => $category->id));
}
This was missing in my function of hook, so there was no value for category ID, thanks UnLoCo for the idea where to look.

Apply Prestashop Cart to custom Hook

First let me explain myself. I'm new to Prestashop Development, I've a background using Wordpress. The thing is, I'm trying to hook 'blockcart.php' to my custom hook 'HOOK_SHOPPINGBAG'. I have tried a lot and after a couple of hours I have decided to just ask the question here.
First I have created the Hook inside ps_hook inside the Prestashop Database. This hook is functioning and Prestashop reads it. After that I have added my new hook to FrontController.php, the code is shown below:
public function initContent()
{
$this->process();
if (!isset($this->context->cart))
$this->context->cart = new Cart();
if (!$this->useMobileTheme())
{
// These hooks aren't used for the mobile theme.
// Needed hooks are called in the tpl files.
$this->context->smarty->assign(array(
'HOOK_HEADER' => Hook::exec('displayHeader'),
'HOOK_TOP' => Hook::exec('displayTop'),
'HOOK_SHOPPINGBAG' => Hook::exec('displayShoppingBag'),
'HOOK_LEFT_COLUMN' => ($this->display_column_left ? Hook::exec('displayLeftColumn') : ''),
'HOOK_RIGHT_COLUMN' => ($this->display_column_right ? Hook::exec('displayRightColumn', array('cart' => $this->context->cart)) : ''),
));
}
else
$this->context->smarty->assign('HOOK_MOBILE_HEADER', Hook::exec('displayMobileHeader'));
}
I also have added the Hook to the second bunch of lines inside FrontController.php:
// Call hook before assign of css_files and js_files in order to include correctly all css and javascript files
$this->context->smarty->assign(array(
'HOOK_HEADER' => $hook_header,
'HOOK_TOP' => Hook::exec('displayTop'),
'HOOK_SHOPPINGBAG' => Hook::exec('displayShoppingBag'),
'HOOK_LEFT_COLUMN' => ($this->display_column_left ? Hook::exec('displayLeftColumn') : ''),
'HOOK_RIGHT_COLUMN' => ($this->display_column_right ? Hook::exec('displayRightColumn', array('cart' => $this->context->cart)) : ''),
'HOOK_FOOTER' => Hook::exec('displayFooter')
));
I want to show the Cart inside header.tpl so I have added the Hook to this file:
<div class="shoppingbag">
{$HOOK_SHOPPINGBAG}
</div>
To make sure Blockcart.php can be hooked to my new hook I have added the following line to blockcart.php:
public function hookShoppingBag($params) {
return $this->hookheader($params, 'displayShoppingBag');
}
I've already tried so many things, but when I try to Hook the module to the new Hook it keeps telling me "This modules can't transplant to this hook!"
Maybe I have just made some stupid mistakes, but anyway I hope you guys can help me. Thanks!
I assume you need a custom hook for blockcart module to be placed somewhere.
This is how to achieve it through Presta's custom hook way.
|| $this->registerHook('shoppingBag') == false
Add this to the module's install method.
public function install()
{
if (
parent::install() == false
|| $this->registerHook('top') == false
|| $this->registerHook('header') == false
|| $this->registerHook('actionCartListOverride') == false
|| Configuration::updateValue('PS_BLOCK_CART_AJAX', 1) == false
|| Configuration::updateValue('PS_BLOCK_CART_XSELL_LIMIT', 12) == false)
|| $this->registerHook('shoppingBag') == false
return false;
return true;
}
Create a public method hookShoppingBag like this.
public function hookShoppingBag($params)
{
return $this->hookProductActions($params);
}
To hook it to any tpl use this.
<div class="shoppingbag">
{hook h='presetWishlist'}
</div>

Opencart how to test if module is assigned for a custom layout?

I have created a module and assigned that to custom layout (Route - product/category).
In this page i need to show only module contents.
So is there any way to do check if module is assigned to current layout ?
SOmething like below,
if ($current module = "Product_list") {
// Dont display products
}
else {
// Else display products
}
If you're coding this into the module code itself, you just need to check the current route
if(!empty($this->request->get['route']) && $this->request->get['route'] == 'product/category') {
... Code ...
} else {
... Code ...
}