Woocommerce Tabs Conditional - if-statement

I running the Woocommerce plugin ( Version 2.013) with Woocommerce Tab Manager extension (Version 1.08). Also Canvas Child Theme (Version 0.1.0)
I'm trying only show certain tabs for certain products using a conditional statement.
The tab manager doesn't allow conditional statements for each tab. It only allows default global tabs or product specific tabs assigned in the product edit page.
I found a decent way to show tabs in the product page based on the a product attribute.
First I thought I share this code because it seems to work. But I'm still wondering if there is a better way to do this?
What I would really like is to create a tab in the Tab Manager and apply the conditional statement to it.
// Video Tabs for Product Page - Activate New Video Tab if Attribute matches
add_filter( 'woocommerce_product_tabs', 'video_tab' );
function video_tab( $tabs ) {
$type = array_shift(woocommerce_get_product_terms($_product->id, 'pa_type', 'names'));
if ( $type == "TypeA" ) {
$video_tab = array( 'video_tab' => array( 'title' => $type.' Video', 'priority' => 9, 'callback' => 'video_tab_func' ) );
return array_merge( $video_tab, $tabs );
}
else {
return $tabs;
}
}
// Tab Desctribtion
function video_tab_func() {
$type = array_shift(woocommerce_get_product_terms($_product->id, 'pa_type', 'names'));
if ( $type == "TypeA" ) {
echo do_shortcode( '[video src="/wp-content/uploads/2013/08/TypeA-video.mp4"]' );
}
}

Related

How to create WizardFormPage dynamically in Sitecore?

We are using the WizardForm xml control for implementing some sort of backend sitecore wizard. We want to add the controls to the pages (or even create new custom pages) on the fly, dynamically depending on the selection done in the previous page.
What I've already done: we called a parent control of the page control on the page (in ActivePageChanging event) and tried to add a new object of type "WizardDialogBaseXmlControl" there. But no new pages are displayed in the frontend. I still see the same number of pages in the browser's dev. tools that I added at design time in xml. I tried "SheerResponse.Redraw()", but that didn't help either.
My next attempt was to create some pages in the xml file at design time and just populate them with controls, but that doesn't work after the wizard has already loaded. Something like "ControlName.Controls.Add(new ControlName())" only works if it is called in the overridden method "OnLoad()".
This code doesn't work:
protected override bool ActivePageChanging(string page, ref string newpage)
{
if (newpage.Equals(Consts.PrototypeDetailsPageId))
{
if (IsFormItemSelected(out var formItem))
{
PrototypeDetailsPanel0.Controls.Add(new Literal("some text"));
}
else
{
SheerResponse.Alert("You must select a form item");
return false;
}
}
return base.ActivePageChanging(page, ref newpage);
}
How can I create a working wizard that adds pages and controls at runtime when they depend on changes on previous pages of the same wizard?
Sitecore WizardForm relies on the newpage parameter to process navigation between steps. So you can prepare alternative versions of wizard steps in advance and set one of them as newpage depending on values entered in the previous step. For example, this is how your code can look like:
protected override bool ActivePageChanging(string page, ref string newpage)
{
if (newpage.Equals(Consts.PrototypeDetailsPageId))
{
if (IsFormItemSelected(out var formItem))
{
newpage = "WizardPageWithAdditionalFields";
}
else
{
SheerResponse.Alert("You must select a form item");
return false;
}
}
return base.ActivePageChanging(page, ref newpage);
}
I also found it useful that wizard forms can be easily created with Interactive Dialogs from PowerShell Extensions.
Just as an alternative solution, here is an example of how you can display multiple dialogs to navigate users through a number of steps:
--Prepare step 1
$options = #{
"A"="a"
"B"="b"
}
$props = #{
Parameters = #(
#{Name="selectedOption"; Title="Choose an option"; Options=$options}
)
Title = "Step 1"
}
--Display step 1
$result = Read-Variable #props
if($result -ne "ok") { exit }
--Step 2
if($selectedOption -eq "Expected value") {
--Perform additional logic, for example modify #props to include additional steps
$props = #{
...
}
}
--Display step 2
$result = Read-Variable #props

Kendo multiselect enable summary tag mode after a few selections are made

I have a kendo multiselect i have set up in summary tag mode with this template:
# if (dataItems.length < 4) { #
# for (var idx = 0; idx < values.length; idx++) {#
#:dataItems[idx].Name#
# if (idx < values.length - 1) {#</li><li class="k-button" unselectable="on"> # } #
#}#
# } else {#
#:values.length# item(s) selected
# } #
This works but it's hacky. What it does is show the first few entries and then group them if you choose four or more. The kendo ui version of this control has a property that allows what i want to do here to work automatically. [kendoMultiSelectSummaryTag]="3"
However that property doesn't seem to be available unless i'm looking in the wrong spot. Can someone tell me how to use it? I would like the default functionality to work because that allows deletions from the selection display.
As far as I can tell there isn't a simple property you can set that will do this for you. Fortunately the solution isn't too tricky. The idea will be to set the default tagMode to 'multiple' (which is it by default), then to create an event handler which will change the tagMode to 'single' when the number of items is crosses your threshold.
Your multiselect definition will need to attach the event handler to the change event:
#(Html.Kendo().MultiSelect()
.Name("multiSelect")
// other properties as needed of course
.Events(events => events
.Change("tagModeSet")
)
)
The javascript event handler will then look something like this:
function tagModeSet() {
// Get the currently selected values and tagMode
var selectedValues = this.value();
var currentTagMode = this.options.tagMode;
var newTagMode = currentTagMode;
// Test to see if you have crossed the threshold
if (selectedValues.length <= 3) {
newTagMode = "multiple";
} else {
newTagMode = "single"
}
// Update the tagMode if needed
if (newTagMode != currentTagMode) {
this.value([]);
this.setOptions({
tagMode: newTagMode
});
this.value(selectedValues);
}
}
Note that when you update the tagMode you first clear the items, then adjust the mode, then re-select the items. Hope that helps.
Reference

Apex5, tick all and untick all checkbox

I want a checkbox in an Interactive Report (IR), and I want the users to be able to quickly Select All or Unselect All of them with a single checkbox in the header.
Added java scripted code but it's not working any idea .....
if ( $( '#selectunselectall' ).is(':checked') ) {
$('input[type=checkbox][name=f01]').attr('checked',true);
Else
$('input[type=checkbox][name=f01]').attr('checked',false);
Add the checkbox to the query, e.g. apex_item.checkbox(1, record_id) as selected.
Set the region Static ID to some value, e.g. myreport
Set the following attributes of column “SELECTED”:
Heading = <input type="checkbox" id="selectunselectall">
Escape Special Characters = No
Enable Users To = (uncheck all options, including Hide, Sort, etc.)
Add a Dynamic Action:
Event = Change
Selection Type = jQuery Selector
jQuery Selector = #selectunselectall
Event Scope = Dynamic
Static Container (jQuery Selector) = #myreport
True Action = Execute JavaScript Code
Fire On Page Load = No
Code =
if ($( '#myreport #selectunselectall' ).is(':checked')) {
$('#myreport input[type=checkbox][name=f01]').attr('checked',true);
} else {
$('#myreport input[type=checkbox][name=f01]').attr('checked',false);
}
Amendment made to jeff's code:
if ($( '#myreport #selectunselectall' ).is(':checked')) {
$('#myreport input[type=checkbox][name=f01]').prop('checked',true);
} else {
$('#myreport input[type=checkbox][name=f01]').prop('checked',false);
}
jQuery API - .prop()
Jeff Kemp's select/unselect all
Have a look at the above link. Jeff Kemp has done a great job documenting your objective.

JomSocial - Registration Redirection

I am working on jomsocial. I have installed the "Redirect Registration for JomSocial" plugin for redirecting the registration page to jomsocial registration. I am getting the registration page but once the first step in registration in completed the page redirects to login page showing the message as "Please Login first".
This is happens only if I disables the menu "Jomsocial" that is created during jomsocial installation.
Is there any other way to redirect the registration page to jomsocial registration.
It seems that you have menu item issue. probably you create some menu items outside JomSocial toolbar and you've set for one of this menu item (the one with highest menu item ID) privacy restriction.
So You get to registration page and when clicking next Joomla! is taking menu item ID from menu item I mentioned above... this cause redirection to "Please, login first". Just check your menu items ;)
You may not disable the jomsocial menu items, if you don't want to show them just put them in a new menu, which you won't create a module for (or create a module and don't assign it to any position). This is why it's failing now. The function requiring this is getMenuItem() in the redirect plugin.
What you will find next is that a visitor clicking on a link that requires login will be sent to the login page with a &return parameter with the encoded url it's supposed to go back to after login. This is not handled by jomsocial plugin, just change is like this:
file plugins/system/jomsocialredirect/jomsocialredirect.php
/**
* Method to override Login / Logout redirect
*/
private function overrideRedirectLoginLogout() {
$mainframe =& JFactory::getApplication();
$task = JRequest::getVar ( 'task' );
switch ($task) {
case 'user.login' : //Joomla 1.6 and later
case 'login' : /* on logging */
/**
* krz This next line restores working status of login redirects.
* (the purpose of jomsocialredirect plugin is to redirect after login, but some links for guests
* point to com_login with a return url set; if this is the case, the next line makes the feature work,
* otherwise it would be overridden;
* note: redirect is to be avoided on logout.
*/
if (JRequest::getVar('return','')!='') return;
if ($this->login ()) { /* we do login by self */
/* redirect if login success */
$link = $this->getMenuLink ( $this->pluginParams->get ( 'redirect_login', 1 ) );
$mainframe->redirect ( $link, JText::_ ( $this->pluginParams->get ( 'redirect_login_msg', 'LOGIN_SUCCESSFUL' ) ), 'message' );
} else {
/* redirect if login failed */
$link = $this->getMenuLink ( $this->pluginParams->get ( 'redirect_login_failed', 1 ) );
$mainframe->redirect ( $link, JText::_ ( $this->pluginParams->get ( 'redirect_login_failed_msg', 'LOGIN_FAILED' ) ), 'notice' );
}
break;
case 'user.logout' : //Joomla 1.6 and later
case 'logout' :
$link = $this->getMenuLink ( $this->pluginParams->get ( 'redirect_logout', 1 ) );
JFactory::getApplication ()->logout ();
$mainframe->redirect ( $link, JText::_ ( $this->pluginParams->get ( 'redirect_logout_msg', 'YOU_HAVE_LOGGED_OUT' ) ), 'message' );
break;
default :
/* override redirect after login / logout */
$view = JRequest::getVar('view','');
if ($view=='profile') {
$link = $this->getMenuLink ( $this->pluginParams->get ( 'redirect_login', 1 ) );
$mainframe->redirect ( $link);
}
break;
}
}

CKeditor - Custom tags and symbols inside the editorwindow

When you insert a flash object into the CKeditor the editor window will show this symbol:
I was wondering. Is it possible to do something similar when users inserts this tag into the editor (using regex {formbuilder=(\d+)}/ ):
{formbuilder=2}
If so, could someone please explain how to? :)
UPDATE:
I've been looking at the PageBreak plugin to try and understand what the hell is going on. The big difference between this plugin and mine is the way the HTML is inserted into the editor.
CKEDITOR.plugins.add('formbuilder',
{
init: function(editor)
{
var pluginName = 'formbuilder';
var windowObjectReference = null;
editor.ui.addButton('Formbuilder',
{
label : editor.lang.common.form,
command: pluginName,
icon: 'http://' + top.location.host + '/publish/ckeditor/images/formbuilder.png',
click: function (editor)
{
if (windowObjectReference == null || windowObjectReference.closed){
var siteid = $('#siteid').val();
windowObjectReference = window.open('/publish/formbuilder/index.php?siteid='+siteid,'Formbuilder','scrollbars=0,width=974,height=650');
} else {
windowObjectReference.focus();
}
}
});
}
});
As you can see, my plugin opens a new window and the tag is inserted with:
function InsertForm(form_id)
{
// Get the editor instance that we want to interact with.
var oEditor = CKEDITOR.instances.page_content;
// Check the active editing mode.
if ( oEditor.mode == 'wysiwyg' )
{
// Insert the desired HTML.
oEditor.insertHtml( '{formbuilder='+form_id+'}' );
}
else
alert( 'You must be on WYSIWYG mode!' );
}
The PageBreak plugin does everything when you click on the toolbar icon. This makes it possible to make the fakeImage inside the plugin file. For me on ther other hand, I don't see how this is possible :\
I'm looking to solve a similar issue, except that all my stuff looks like XML. So like, <cms:include page="whatever" />. In your case, you would be able to copy the placeholder plugin and change the placeholder regex to match your tags. In my case, looks like I'll be modifying the iframe plugin or something, and hopefully figuring out how to add each of my tags as self-closing...