Editable Breadcrumb for Dynamic Pages - zend-framework

Looking for a better Breadcrumb solution for a Zend Framework project.
Currently I have a navigation.xml like
<?xml version="1.0" encoding="UTF-8"?>
<configdata>
<nav>
<home>
<label>Home</label>
<module>default</module>
<controller>index</controller>
<action>index</action>
<pages>
<countryurl>
<label>Spain</label>
<module>default</module>
<controller>country</controller>
<action>index</action>
<route>country_url</route>
<params>
<country>spain</country>
</params>
<pages>
<provinceurl>
<label>Madrid</label>
<module>default</module>
<controller>country</controller>
<action>province</action>
<route>province_url</route>
<params>
<country>spain</country>
<province>madrid</province>
</params>
<pages>
<cityurl>
<label>City</label>
<module>default</module>
<controller>country</controller>
<action>city</action>
<route>city_url</route>
<params>
<country>spain</country>
<province>madrid</province>
<city>madrid</city>
</params>
<pages>
<producturl>
<label>Product</label>
<module>default</module>
<controller>country</controller>
<action>product</action>
<route>product_url</route>
<params>
<country>spain</country>
<province>madrid</province>
<city>madrid</city>
<product>product</product>
</params>
</producturl>
</pages>
</cityurl>
</pages>
</provinceurl>
</pages>
</countryurl>
</pages>
</home>
</nav>
</configdata>
and routes like
$router->addRoute(
'product_url',
new Zend_Controller_Router_Route(':lang/:country/:province/:city/:product', array(
'controller' => 'country',
'action' => 'product'
))
);
$router->addRoute(
'city_url',
new Zend_Controller_Router_Route(':lang/:country/:province/:city', array(
'controller' => 'country',
'action' => 'city'
))
);
$router->addRoute(
'province_url',
new Zend_Controller_Router_Route(':lang/:country/:province', array(
'controller' => 'country',
'action' => 'province'
))
);
$router->addRoute(
'country_url',
new Zend_Controller_Router_Route(':lang/:country', array(
'controller' => 'country',
'action' => 'index'
))
);
I am facing some issues / looking for some suggestions . Creating the Breadcrumbs with the help of Zend_Navigation
$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
$container = new Zend_Navigation($config);
$view->navigation($container);
1 ) The request for http://example.com/en/spain/madrid/madrid/product shows the breadcrumb, with the help of
$this->navigation()
->breadcrumbs()
->setMinDepth(0)
->setLinkLast(true)
->setSeparator(" > ");
as Home > Spain > Madrid > City > Product
But the links pointing at Spain , Madrid , City all are to http://example.com . Which should be http://example.com/en/spain , http://example.com/en/spain/madrid , http://example.com/en/spain/madrid/madrid respectively.
2 ) Currently when the request for http://example.com/en/spain
the breadcrumb will show Home >> Spain
<label>Spain</label>
<module>default</module>
<controller>country</controller>
<action>index</action>
<route>country_url</route>
<params>
<country>spain</country>
</params>
But you can see the param country differs according to country. So do we want to add the labels for all countries ?
http://example.com/en/spain
Home >> Spain
http://example.com/en/india
Home >> India
I have provinces , city and product coming along, any suggestions how I can build for it ?
Also this is a multilingual website, so how can we make the necessary changes to the label? I guess if we are using Zend_Translate it will make the necessary changes.

You can create your own page class that treats params beginning with : as dynamic. You can reference it in the nav configuration like
...
<countryurl>
<label>:country</label> <!-- dynamic -->
<module>default</module>
<controller>index</controller>
<action>index</action>
<route>country_url</route>
<type>DynamicNavPage</type> <!-- page classname -->
<params>
<country>:country</country> <!-- dynamic -->
</params>
<pages>
...
and for example
<?php
class DynamicNavPage extends Zend_Navigation_Page_Mvc {
/**
* Params with ":" are read from request
*
* #param array $params
* #return Zend_Navigation_Page_Mvc
*/
public function setParams(array $params = null) {
$requestParams = Zend_Controller_Front::getInstance()
->getRequest()->getParams();
//searching for dynamic params (begining with :)
foreach ($params as $paramKey => $param) {
if (substr($param, 0, 1) == ':' &&
array_key_exists(substr($param, 1), $requestParams)) {
$params[$paramKey] = $requestParams[substr($param, 1)];
}
}
return parent::setParams($params);
}
/**
* If label begining with : manipulate (for example with Zend_Tanslate)
*/
public function setLabel($label) {
if (substr($label, 0, 1) == ':') {
//label modifications go here
//as an example reading it from page params and capitalizing
//can use Zend_Translate here
$requestParams = Zend_Controller_Front::getInstance()
->getRequest()->getParams();
$labelParamKey = substr($label, 1);
if (array_key_exists($labelParamKey, $requestParams)) {
$label = ucfirst($requestParams[$labelParamKey]);
}
}
return parent::setLabel($label);
}
}

Related

How to import XML feed with grandchildren subgroup?

I have this xml feed ...
<products>
<product>
<manufacturer_name>2CARS</manufacturer_name>
<quantity>1081</quantity>
<price>2.25</price>
<ean13>8586017592520</ean13>
<reference>92520</reference>
<weight>0.01</weight>
<descriptions>
**<descriptions>**
<description>LED Autožiarovka 2LED 12V 5050SMD T10, biela.</description>
<description_short>LED Autožiarovka</description_short>
<name>4CARS LED ŽIAROVKA 2LED 12V 5050SMD T10</name>
**</descriptions>**
</descriptions>
<images>
<image>
https://2cars.eu/upload/products-import/hd/92520_01.jpg
</image>
</images>
<default_category>
<category_default_name>LED žiarovky</category_default_name>
</default_category>
<product_category_tree>Elektro a Hifi > Osvetlenie > LED žiarovky</product_category_tree>
<hmotnos__>0.0094</hmotnos__>
<balenie>2 ks</balenie>
<farba/>
</product>
<products>
... and this part of script ...
{
$product_description[] = array(
'product_id' => $product_id,
'lang_id' => $lang_id,
'name' => (string) $product->name,
'url' => url( (string) $product->name ),
'short_info' => (string) $product->description_short,
'description' => (string) $product->description
);
}
.. the result is:
can not be imported, I guess because the grandchildren subgroup is hidden to it, but how to let him know to use it.
Please, can anybody help me?

Magento 2 - Custom Action for Catalog Rule

I need to create custom action for the Catalog Price Rule. Not the whole custom Catalog Rule, but just action, which I can select. The purpose of this action is simply recalculating product prices based on some criterias.
How can I achieve it?
To achieve your requirement try with the below steps.
In your custom module override the catalog_rule_form.xml
Inside catalog_rule_form.xml find the below fieldset
<fieldset name="actions" sortOrder="30">
Inside the above actions fieldset, you can find the existing rules which are predefined and then add your custom rule as below.
<rule name="4">
<value>custom_action</value>
<actions>
<action name="0">
<target>catalog_rule_form.catalog_rule_form
.actions.discount_amount</target>
<callback>setValidation</callback>
<params>
<param name="0" xsi:type="string">validate-number-range</param>
<param name="1" xsi:type="string">false</param>
</params>
</action>
</actions>
</rule>
2) Next Override
Magento\CatalogRule\Model\Rule\Action\SimpleActionOptionsProvider.php
<?php
namespace Magento\CatalogRule\Model\Rule\Action;
class SimpleActionOptionsProvider implements
\Magento\Framework\Data\OptionSourceInterface
{
/**
* #return array
*/
public function toOptionArray()
{
return [
[
'label' => __('Apply as percentage of original'),
'value' => 'by_percent'
],
[
'label' => __('Apply as fixed amount'),
'value' => 'by_fixed'
],
[
'label' => __('Adjust final price to this percentage'),
'value' => 'to_percent'
],
[
'label' => __('Adjust final price to discount value'),
'value' => 'to_fixed'
],
[
'label' => __('Custom Action'),
'value' => 'custom_action'
]
];
}
}
Result:
[enter image description here][1]
[1]: https://i.stack.imgur.com/EjG19.png

TYPO3 - Custom extension : show in flexform

I made my own extension on TYPO3 6.2 with the Extension Builder, the goal is to let the backend users create events (with name, location, date, number of people etc...) of our company.
I created a backend plugin, it works good.
I created a frontend plugin, but I don't know how to write my flexform file in order to let the backend users choose which event to display (through the "show" action I guess)... Best result would be to get a select list with all existing events.
How to do it ?
In my ext_localconf.php, I have :
<?php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Mycompany.' . $_EXTKEY,
'Displayevent',
array(
'Event' => 'show',
),
// non-cacheable actions
array(
'Event' => 'show',
)
);
?>
but in frontend there is a Typo3 error :
1298012500: Required argument "event" is not set for Mycompany\MycompanyEvents\Controller\EventController->show
here my showAction() code :
/**
* action show
*
* #param \MyCompany\mycompany_events\Domain\Model\Event $event
* #return void
*/
public function showAction(\MyCompany\mycompany_events\Domain\Model\Event $event) {
$this->view->assign('event', $event);
}
Try to follow below steps to call flexform.
in your ext_tables.php file add below code.
//extenstion name
$extensionName = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($_EXTKEY);
//plugin integration
$frontendpluginName = 'your_plugin_name';
$pluginSignature = strtolower($extensionName) . '_'.strtolower(
$frontendpluginName
);
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
$pluginSignature,
'FILE:EXT:' . $_EXTKEY . '/Configuration/FlexForms/configure_plugin.xml'
);
Now, create flexform file in this directory /Configuration/FlexForms/ like below and use userFunct for event select list.
<T3DataStructure>
<sheets>
<!--
################################
SHEET General Settings
################################
-->
<sDEF>
<ROOT>
<TCEforms>
<sheetTitle>General</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<settings.variable_name>
<TCEforms>
<label>Title</label>
<config>
<type>select</type>
<itemsProcFunc>EXT:ext_key/Classes/Utility/class.tx_event_utility.php:tx_event_utility->getEventList</itemsProcFunc>
<multiple>0</multiple>
<minitems>0</minitems>
<maxitems>50</maxitems>
<size>5</size>
</config>
</TCEforms>
</settings.variable_name>
</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
Now, Create tx_event_utility.php file on this path /ext_key/Classes/Utility/ like below.
<?php
class tx_event_utility {
protected $objectManager;
protected $configurationManager;
protected $pluginSetting;
protected $objectCategoryRepository;
function __construct() {
$this->objectManager = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
$this->configurationManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
$this->pluginSetting = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
$this->objectCategoryRepository = $this->objectManager->get('added repositry namespace');
}
function getEventList($config, $item) {
// write code for geting event list
}
return $config;
}
}
?>
Add file Yourext/Configuration/TCA/Overrides/tt_content.php
<?php
defined('TYPO3_MODE') or die();
// register plugin and flexform
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'yourext',
'Name',
'LLL:EXT: yourext/Resources/Private/Language/locallang_be.xlf:name_plugin'
);
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['yourext_name'] = 'select_key';
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['yourext_name'] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
'yourext_name',
'FILE:EXT:yourext/Configuration/FlexForms/flexform.xml'
);

Magento Customer Login Notification Email Sent to Customer

Is there an easy solution for the customer to receive a notification email every time login to the store?
i am creating extension
app/etc/Module Custom_Notify.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Custom_Notify>
<active>true</active>
<codePool>local</codePool>
</Custom_Notify>
</modules>
</config>
app/code/local/Custom/Notify/etc config.xml
<?xml version="1.0"?>
<config>
<modules>
<Custom_Notify>
<version>0.1.0</version>
</Custom_Notify>
</modules>
<frontend>
<events>
<customer_login>
<observers>
<cnotify>
<type>model</type>
<class>cnotify/observer</class>
<method>customerNotify</method>
</cnotify>
</observers>
</customer_login>
</events>
</frontend>
<global>
<helpers>
<cnotify>
<class>Custom_Notify_Helper</class>
</cnotify>
</helpers>
<blocks>
<cnotify>
<class>Custom_Notify_Block</class>
</cnotify>
</blocks>
<models>
<cnotify>
<class>Custom_Notify_Model</class>
</cnotify>
</models>
</global>
</config>
app/code/local/Custom/Notify/Model/Observer.php
<?php
class Custom_Notify_Model_Observer {
public function customerNotify($observer) {
/* for Template */
$template_id= '1';
$customer = Mage::getSingleton('customer/session')->getCustomer();
$recepient = array(
'name' => $customer->getName(),
'email' => $customer->getEmail()
);
$sender = array(
'name' => Mage::getStoreConfig('trans_email/ident_general/name'),
'email' => Mage::getStoreConfig('trans_email/ident_general/email')
);
$email_template_variables = array(
'customer_name' => $customer->getName(),
'customer_email' => $customer->getEmail()
);
$email_template = Mage::getModel('core/email_template')->loadDefault($template_id);
$storeId = Mage::app()->getStore()->getId();
$email_template->setSenderName($sender['name']);
$email_template->setSenderEmail($sender['email']);
$email_template->send($recepient['email'], $recepient['name'], $email_template_variables,$storeId);
}
}

Render children of active branch with Zend Navigation view helper

What I am asking is similar to this issue, which is still unresolved.
I'm trying to create a good submenu solution, but I can't seem to get Zend_View_Helper_Navigation_Menu to work with me.
Here is my XML navigation config:
<configdata>
<nav>
<index>
<label>Index</label>
<uri>/</uri>
<pages>
<home>
<label>home</label>
<uri>/</uri>
</home>
<about>
<label>about</label>
<uri>/about</uri>
</about>
<works>
<label>works</label>
<uri>/works</uri>
<pages>
<music>
<label>music</label>
<uri>/works/music</uri>
</music>
</pages>
</works>
<posts>
<label>posts</label>
<uri>/posts</uri>
</posts>
<admin>
<label>admin</label>
<uri>/admin</uri>
<pages>
<login>
<label>log in</label>
<uri>/admin/login</uri>
</login>
<settings>
<label>settings</label>
<uri>/admin/settings</uri>
</settings>
<register>
<label>register</label>
<uri>/admin/register</uri>
</register>
<logout>
<label>log out</label>
<uri>/admin/logout</uri>
</logout>
</pages>
</admin>
</pages>
</index>
</nav>
</configdata>
And here is the relevant code in my layout:
echo $this->navigation()->menu()->renderMenu(
null,
array(
'minDepth' => 2,
'maxDepth' => 2,
'onlyActiveBranch' => true
)
);
When I navigate to 'admin', I don't see the submenu. If I change the minDepth to 1 I can see that that menu and its children are 'active' in the source. Why are they not being rendered when the minDepth is set to 2?
I did a workaround for this, but I have to copy/paste it into every controller for it to work (because I need the request object in order to do it):
$pages = $this->view->navigation()->current()->getPages();
foreach ($pages as $page) {
$this->_setChildrenInvisible($page);
}
the _setChildrenInvisible() function:
private function _setChildrenInvisible(Zend_Navigation_Container $container) {
foreach ($container as $child) {
if ($child->hasChildren()) {
$this->_setChildrenInvisible($child);
}
$child->setVisible(false);
}
}
Im just trying to get admin's children to render in the submenu. Does anyone know how to fix this?
In the layout, in the renderMenu method, the renderParents attribute should be set to false
echo $this->navigation()->menu()->renderMenu(
null,
array(
'minDepth' => 2,
'maxDepth' => 2,
'onlyActiveBranch' => true,
'renderParents' => false
)
);
I know this is an old question but it can still be relevant for some people stumbling across this. In ZF2 it can be done the same as in ZF1 using:
echo $this->navigation()->menu()->renderSubMenu();