How to recursive change document's settings in Pimcore? - pimcore

I need to change settings (controller, action and view) in all document in some root. Is some way to do it automatically by admin panel?
Only idea that I have is to write php script to do it.
Thanks in advance.

I have written a function in the root-controller to accomplish this:
private function changeDocumentsSettings() {
foreach ($this->document->getChilds(true) as $child) {
$child->setController('operator-news');
$child->setAction('year-list');
$child->setTemplate('/operatornews/yearlist.php');
$child->save();
foreach($child->getChilds(true) as $gchild) {
$gchild->setController('operator-news');
$gchild->setAction('item');
$gchild->setTemplate('/operatornews/item.php');
$gchild->save();
}
}
}

Related

OpenCart 2.x Change default view to list-view

I would like to permanently set the default view in OpenCart 2.1.0.2 to list-view instead of grid-view. I do not want to give my visitors ability to switch to grid-view; hence I'd like to completely disable grid-view and keep only list-view. Any assistance would be greatly appreciated.
You can do that using two methods for default list view.
1st method: replace following code (catalog/view/javascript/common.js)
if (localStorage.getItem('display') == 'list') {
$('#list-view').trigger('click');
} else {
$('#grid-view').trigger('click');
}
and using the following code in place
if (localStorage.getItem('display') == 'grid') {
$('#grid-view').trigger('click');
} else {
$('#list-view').trigger('click');
}
2nd method: If you don't want/like to permanently remove grid view then remove the code in (catalog/view/javascript/common.js) and make following code in common.js only
$('#grid-view').trigger('click');

How to Conditionally remove Block or Container from Layout programatically?

If any one want to remove container (block) like product.info.main from Product Detail Page based on certain conditions or product has attribute with value assigned.
Then what is the best approach for achieving This?
Thanks
We can use Event Observer approach...
In YOUR_VENDOR\YOUR_MODULE\etc\frontend\events.xml file, need to add below code:
<event name="layout_generate_blocks_after">
<observer name="personalize-theme-pdp-customize" instance="YOUR_VENDOR\YOUR_MODULE\Observer\ApplyThemeCustomizationObserver" />
</event>
And in YOUR_VENDOR\YOUR_MODULE\Observer\ApplyThemeCustomizationObserver.php file, need to add below code:
public function execute(Observer $observer)
{
$action = $observer->getData('full_action_name');
if ($action !== 'catalog_product_view') {
return;
}
$product = $this->_registry->registry('product');
if ($product) {
$attribute = $product->getCustomAttribute('g3d_app_url_default');
if ($attribute && $attribute->getValue()) {
/** #var \Magento\Framework\View\Layout $layout */
$layout = $observer->getData('layout');
$layout->unsetElement('product.info.main');
}
}
}
Using a site wide event to remove a container/block from a specific page is overkill and not the best approach because your condition will be evaluated with every page load, adding a slight overhead to all the pages.
Removing a container/block from a specific page is best achieved by creating an after plugin for the execute method of the controller of the page where you want to remove the container/block. With this approach your condition is only executed when the intended page is loaded.
public function afterExecute(\Magento\[Module]\Controller\[ControllerName] $subject, $result)
{
if ([your condition]) {
$result->getLayout()->unsetElement('name_of_container_or_block');
}
return $result;
}

How do I remove role="search" from the form-tag in drupal?

I am new to Drupal. I have developed one site . But in WCAG 2.0 testing I was getting following problem: Element 'form' does not need a 'role' attribute. How do I achive this ? Please Help...
Thanks.
Here is my source code:
enter image description here
You can do that by using hook_form_alter. You need to try this code with your custom module.
function hook_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'search_block_form') {
$form["#attributes"]["role"] = "";
//Or
unset($form["#attributes"]["role"]);
}
}
You need to create a custom module at 'sites/all/modules' directory and in the .module file you need to write this function replacing the hook with module name.
For example, create a custom module with the name custom. See this article if needs help. In the modules's custom.module file write the following function:
function custom_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'search_block_form') {
$form["#attributes"]["role"] = "";
//Or
unset($form["#attributes"]["role"]);
}
}
Hope that helps!

How do I track whether a context menu item is already created by my Chrome Extension?

There are only four methods for chrome.contextMenus:
create
update
remove
removeAll
I am wondering how do I check whether one menu is already created?
I tried this:
try {
chrome.contextMenus.update("byname", {});
} catch (e) {
// doesn't exist
}
But it seems the error cannot be caught (but shown in the console).
Thanks for any kind of tips!
Each chrome.contextMenus.create call returns an unique identifier. Store these identifiers in an array or hash to keep track of them.
This is a direct solution to anyone having the op's problem, based on the suggestion by Rob W. The idea is to maintain your own list of existing context menu id's.
By using these wrapper functions to maintain context menu entries, also the removal and updates are being kept track of (addressing Fuzzyma's comment).
Usage works like Chrome's own methods, eg. createContextMenu({id: "something"}, onclick). It works for me.
let contextMenus = {}
// method to create context menu and keep track of its existence
function createContextMenu() {
if (arguments[0] && arguments[0].id) {
// TODO: not sure if this will work properly, is creation synchronous or asynchrounous?
// take in to account calll back and the runtime error?
chrome.contextMenus[arguments[0].id] = chrome.contextMenus.create.apply(null, arguments);
}
}
function updateContextMenu() {
if (arguments[0] && contextMenus[arguments[0]]) {
chrome.contextMenus.update.apply(mull, arguments);
}
}
function removeContextMenu() {
if (arguments[0] && contextMenus[arguments[0]]) {
chrome.contextMenus.remove.apply(null, arguments);
contextMenus[arguments[0]] = undefined;
}
}
function contextMenuExists(id) {
return !!contextMenus[id];
}

Magento: Remove a Shipping Method in Frontend

I'm currenty working on a shipping module extension that is used for an order-import script to set to every order the same shipping cost and shipping code.
Everythings works fine but the problem that is, that the shipping method is visible in frontend. I will release this extension later in magento connect, so its not pissible to edit frontend templates.
Does anyone know how to disable the carrier in frontend without disableing the module in backend or changeing the status to inactive and without editing templates? (e.g. a custom block that declines displaying)
Thanks to everyone! Mru
EDIT:
I've tried your tip like this, but it doesn't work:
<blocks>
<checkout>
<rewrite>
<onepage_shipping_method_availible>XXX_XXX_Block_Checkout_Onepage_Shipping_Method_Available</onepage_shipping_method_availible>
</rewrite>
</checkout>
</blocks>
and created this class:
class XXX_XXX_Block_Checkout_Onepage_Shipping_Method_Available extends Mage_Checkout_Block_Onepage_Shipping_Method_Available
{
public function getShippingRates()
{
if (empty($this->_rates)) {
$this->getAddress()->collectShippingRates()->save();
$groups = $this->getAddress()->getGroupedAllShippingRates();
return $this->_rates = $groups;
}
return $this->_rates;
}
}
(I don't know why it is not displayed correctly...)
Thanks for your held, MRu
EDIT2:
Sorry for being so stupid.. The above posted code would work if i were not unable to write 'availalbe'...
Thanks!
You can hide shipping method from front end with observer, write this code in config.xml
<frontend>
<events>
<sales_quote_collect_totals_before>
<observers>
<frontend_shipping_rates_sales_quote_collect_totals_before>
<class>yourmodule/observer</class>
<method>hideShippingMethods</method>
</frontend_shipping_rates_sales_quote_collect_totals_before>
</observers>
</sales_quote_collect_totals_before>
</events>
Second in Observer.php use this code
public function hideShippingMethods( Varien_Event_Observer $observer )
{
if (Mage::getDesign()->getArea() === Mage_Core_Model_App_Area::AREA_FRONTEND)
{
$quote = $observer->getEvent()->getQuote();
$store = Mage::app()->getStore($quote->getStoreId());
$carriers = Mage::getStoreConfig('carriers', $store);
$hiddenMethodCode = 'freeshipping';
foreach ($carriers as $carrierCode => $carrierConfig)
{
if( $carrierCode == $hiddenMethodCode )
{
$store->setConfig("carriers/{$carrierCode}/active", '0');
}
}
}
}
You need to overload the Mage_Checkout_Block_Onepage_Shipping_Method_Available::getShippingRates() method

Resources