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

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 ...
}

Related

Laravel change boolean depending on route

I created a landing page using VueJS, and wrote a script to change the app bars elevation depending on whether the user is on the home page or not. However, I now need to convert all of this into laravel, and everything else works apart from the ability to change the elevation depending on the link. This is the code I am using currently, how would I translate that into laravel?
watch: {
'$route'() {
if (this.$route.path === '/') {
this.isFlat = false
}
else {
this.isFlat = true
}
}
}

Load component/template depending on the route param vuejs

I would like to ask if can I implement this on vuejs, so basically the code will load a page/template base on the param url. I've been searching for a while and can't get the results I need or maybe I'm just searching a wrong keyword.
My url is like this, so I just can't manually declare the url in my route because it is dynamic, fetch from the database.
path: '/user/page_type
Thank you very much!
export default {
mounted () {
if(this.$routes.params.page_type == "home"){
// Load Homepage Here
// ../../../page/HomePage.vue
}
else if(this.$routes.params.page_type == "speaker"){
// Load Speakerpage Here
// ../../../page/HomePage.vue
}
else if(this.$routes.params.page_type == 'html'){
// Load HTML Page Here
// ../../../page/HtmlPage.vue
}
}
}
This is available out of the box within official addon vue-router.
Docs for your case: link

defining page after issubmit

Im writting my first module in Prestashop. When I submit data in backoffice it loads the configuration page of my module. But I want to stay at the form. How can I achieve this?
if (Tools::isSubmit('toggleanswers')) {
$id_answer = Tools::getValue('id_answer');
if($this->toggleAnswer($id_answer)) {
$this->_html .= $this->displayConfirmation($this->l('Entry status changed'));
}
else {
$this->_html .= $this->displayError(implode($this->_errors, '<br />'));
}
}
This is how my function looks like. After Clicking on toggle it shouldn't return to configuration page... The url of my form looks like this: /index.php?controller=AdminModules&configure=questions&module_name=questions&id_question=1&updatequestions&token=ccd237618500f4c18f42d1a4fe971aa9
If I understand what do you want, you should change your code in this:
if (Tools::isSubmit('toggleanswers')) {
$id_answer = Tools::getValue('id_answer');
if($this->toggleAnswer($id_answer)) {
Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true).'&conf=6&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name.'&id_question='.$id_question.'&update_questions');
}
else
{
$this->_html .= $this->displayError(implode($this->_errors, ''));
}
}
If you have managed good the post process and if is all ok you should redirected on the form of your 'question' with default message of changed status otherwise it will display the errors.

How to remove delivery shipping step on prestashop 1.6.1?

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');

Make menu tab on user profile visible only to profile owner

I made a "My bookmarks" tab on the user profile page using Views. The tab shows nodes the user has flagged.
However - "My bookmarks" should only be visible on the user's own profile page and at the moment the "My bookmarks" tab is visible on every profile a user visits. How do I check whether the current user matches the profile being viewed? I tried that from the View interface, but the access permissions don't have any options that work.
EDIT:
I think it is this code, but I still need some guidelines as to how to implement that:
<?php
global $user;
if (arg(0) == 'user' && $user->uid == arg(1)){
return TRUE;
}
else {
return FALSE;
}
?>
I also found this module, I think it helps a lot Views Access Callback
I managed to solve this using the code and module from above.
The custom module contains this code
<?php
function MYMODULE_views_access_callbacks() {
return array(
'MYCALLBACK_user_has_access' => t('User can only see tab on his own profile'));
}
function MYCALLBACK_user_has_access() {
global $user;
if (arg(0) == 'user' && $user->uid == arg(1)){
return TRUE;
}
else {
return FALSE;
}
}
?>
The Views Access Callback module adds your callback to the Views interface and from there, you can use it for your own view.