aoepeople/aoe_sessionvars

捕获外部传入的变量

安装: 560

依赖: 0

建议者: 0

安全: 0

星标: 5

关注者: 39

分支: 2

开放问题: 0

类型:magento-module

v0.3.2 2015-09-17 20:10 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:31:28 UTC


README

描述

本模块的目的是提供一个通用的方式来“捕获”从外部(通过URL参数或cookie)传入的变量,并将它们存储在指定的会话中,以便其他模块可以从那里使用

作者/贡献者

用法

在每次页面访问时,应评估和验证传入变量与正则表达式模式。然后存储在会话中。如果会话中已存在值,且提供了一个新值,则新值应覆盖现有值。

工作原理

在需要设置会话的模块的config.xml中添加变量

<frontend>
	<aoe_sessionvars>
		<vars>
			<var1><!-- this is the internal name of the variable that's used to store/access the value from the core/customer/checkout session -->
				<getParameterName /><!-- if empty this parameter can't be captured by url -->
				<cookieName /><!-- if empty this parameter can't be captured by cookie -->
				<validate /> <!-- Regular expression to validate the value of parameter -->
				<scope /><!-- if empty core will be used -->
				<defaultValue /><!-- fallback if parameter wasn't captured before -->
				<defaultValue_STOREID /><!-- fallback if parameter wasn't captured before. Replace the storeId with actual STORE ID -->
			</var1>
		</vars>
	</aoe_sessionvars>
</frontend>

示例

<frontend>
	<aoe_sessionvars>
		<vars>
			<coupon_code>
				<getParameterName>cp</getParameterName>
				<cookieName>MAGENTO_CP</cookieName>
				<validate><![CDATA[/^[^$|\s+$]/]]></validate>
				<scope>customer</scope>
			</coupon_code>
		</vars>
	</aoe_sessionvars>
</frontend>

在上面的示例中,如果URL包含参数为'cp'或'MAGENTO_CP'cookie被设置,则'cp'或'MAGENTO_CP'的值将设置在指定的会话(范围)中。

它还提供了一个概念,可以轻松地在CMS块(或其他用模板过滤器处理的文本)中消费会话变量。

示例

传入请求:http://www.example.com/?lang=en-ca&country=ca

CMS内容:点击这里

<frontend>
	<aoe_sessionvars>
		<country>
			<getParameterName>country</getParameterName>
			<cookieName />
			<validate><![CDATA[/^[A-Za-z]{2}$/]]></validate>
			<scope />
			<defaultValue>en</defaultValue>
			<defaultValue_1>en-us</defaultValue_1>
		</country>
		<lang>
			<getParameterName>lang</getParameterName>
			<cookieName />
			<validate><![CDATA[/^([A-Za-z]{2})-([A-Za-z]{2})$/]]></validate>
			<scope />
			<defaultValue>en-us</defaultValue>
		</lang>
	</aoe_sessionvars>
</frontend>