I'm trying to show last 150 added products.
I'm creating the module and add in xml
<reference name="content">
<!-- Add product list to content -->
<block type="newprod/product_list" name="product_list" template="catalog/product/list.phtml">
<!-- Add toolbar to product list -->
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<!-- Add pager to toolbar -->
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<!-- Specify toolbar block name -->
<action method="setToolbarBlockName">
<name>product_list_toolbar</name>
</action>
<!-- Use custom product collection -->
<action method="setCollection">
<value helper="newprod/getProductCollection" />
</action>
<!-- Use custom available sort by orders -->
<action method="setAvailableOrders">
<value helper="newprod/getAvailableOrders" />
</action>
<!-- Set the default sort by order -->
<action method="setSortBy">
<value>price</value>
</action>
<!-- Set default direction to ascending -->
<action method="setDefaultDirection">
<value>asc</value>
</action>
<action method="setColumnCount">
<column>12</column>
</action>
<action method="setLimit"><limit>50</limit></action>
</block>
</reference>
in getProductCollection
public function getProductCollection()
{
$collection = Mage::getResourceModel('reports/product_collection')
->addStoreFilter($store_id)
->addAttributeToFilter('visibility', 4)
->addAttributeToFilter('status', 1)
->addAttributeToSelect('*')
->setVisibility(array(2,3,4))
->setOrder('created_at', 'desc')
->setPage(1, 9);
return $collection;
}
but in result page I get n items on page and it's fine, but pager render for all 10000 products, how can I limit this? I'm trying to play with _beforeToHtml() function from mycomp_NewProd_Block_Product_List extends Mage_Catalog_Block_Product_List but now luck.
Maybe you can add
->setPageSize(150)
before return collection.
Related
I try to create small extension for displaying string in Product page Magento 1.9.2. So I did it using "community" code pool for effecting block (block name ="product.info") in catalog.xml layout but it did not work till. I think my code is right but I don't sure whether all relevant folders (Controller, helper, Observer) are included or not in my module(Dinod). Please any one can help me to create this extension by using "community" code pool in Magento 1.9.2.
I failed to get expected output by testing my extension using "community" code pool. But same extension structure work fine after using "core" code pool. So I stored my module(Dinod) inside "app/code/core/Mage" folder and that time worked properly.
This code structure does not generate any expected output through frontend (product page).
app/etc/modules/Jpdn_Dinod.xml
<config>
<modules>
<Jpdn_Dinod>
<active>true</active>
<codePool>community</codePool>
</Jpdn_Dinod>
</modules>
</config>
app/code/community/Jpdn/Dinod/etc/config.xml
<config>
<modules>
<Jpdn_Dinod>
<version>1.0.3</version>
</Jpdn_Dinod>
</modules>
<frontend>
<layout>
<updates>
<Jpdn_Dinod module="Jpdn_Dinod">
<file>jpdn_dinod.xml</file>
</Jpdn_Dinod>
</updates>
</layout>
</frontend>
<global>
<!-- adding block "Jpdn_Dinod_Block_Product_View" -->
<blocks>
<jpdn_dinod>
<class>Jpdn_Dinod_Block_Product_View</class>
</jpdn_dinod>
</blocks>
<!-- adding block "Jpdn_Dinod_Block_Product_View" -->
</global>
</config>
app/code/community/Jpdn/Dinod/Block/Product/View/dinod.php
class Jpdn_Dinod_Block_Product_View_Dinod extends Mage_Core_Block_Template
{
public function dinod_methodblock()
{
$name = "Informations from dinod_methodblock in Jpdn_Dinod";
return $name;
}
}
app/design/frontend/base/default/layout/jpdn_dinod.xml
<layout version="1.0.3">
<catalog_product_view>
<reference name="product.info">
<!--
<block type="dinod/product_view_dinod" name="mage.view.dinod" as="mage.dinod" template="dinod/product/view/dinod.phtml">
<action method="addToParentGroup"><group>detailed_info</group></action>
<action method="setTitle" translate="value"><value>Dinodddd works</value></action>
</block>
-->
<block type="jpdn_dinod/product_view_dinod" name="jpdn.view.dinod" as="jpdn.dinod" template="dinod/product/view/dinod.phtml">
<action method="addToParentGroup"><group>detailed_info</group></action>
<action method="setTitle" translate="value"><value>Dinodddd works</value></action>
</block>
</reference>
</catalog_product_view>
</layout>
app/design/frontend/base/default/template/dinod/product/view/dinod.phtml
<?php echo $this->dinod_methodblock(); ?>
Above code structure does not generate any expected output through frontend (product page).
After I created new block class file in "app/code/core/Mage" and edited code in template file as below so I got expected output without any error.
app/code/core/Mage/Dinod/Block/Product/View/dinod.php
class Mage_Dinod_Block_Product_View_Dinod extends Mage_Core_Block_Template
{
public function dinod_methodblock()
{
$name = "Informations from dinod_methodblock in Mage_Dinod";
return $name;
}
}
app/design/frontend/base/default/layout/jpdn_dinod.xml
<layout version="1.0.3">
<catalog_product_view>
<reference name="product.info">
<block type="dinod/product_view_dinod" name="mage.view.dinod" as="mage.dinod" template="dinod/product/view/dinod.phtml">
<action method="addToParentGroup"><group>detailed_info</group></action>
<action method="setTitle" translate="value"><value>Dinodddd works</value></action>
</block>
<block type="jpdn_dinod/product_view_dinod" name="jpdn.view.dinod" as="jpdn.dinod" template="dinod/product/view/dinod.phtml">
<action method="addToParentGroup"><group>detailed_info</group></action>
<action method="setTitle" translate="value"><value>Dinodddd works</value></action>
</block>
</reference>
</catalog_product_view>
</layout>
But I want to get same output only using "community" code pool instead of using "core" code pool for effecting block (block name ="product.info") in catalog.xml layout.
Your block definition is wrong
<blocks>
<jpdn_dinod>
<class>Jpdn_Dinod_Block_Product_View</class>
</jpdn_dinod>
</blocks>
this is not how you should declare it. Remove product_view
<class>Jpdn_Dinod_Block</class>
this should be enough
I am working on an Access 2013 database that will have different utility poles entered into the database and linked with other attributes. Each pole will have a unique global ID, and to simplify working I would like to add another unique ID that is more simple. I would like this field auto populated when a new pole in imported into the database. The ID would go as follows:
SAC(year)-(Escalating number, cannot be a duplicate)
ex. SAC16-20 (This would be the 20th pole entered into the database in 2016)
ex. SAC15-2536 (Would be the 2536th pole entered in 2015)
If anyone could help me generate some code to make this auto populate ID field work I would greatly appreciate it.
With Access versions 2010 and later you can use an event-driven data macro to generate the sequential ID. For example, say you have a table named [poledata]. Open it in Design View and add two fields:
alternate_id_seq – Numeric (Long Integer)
alternate_id – Text(20)
Save the changes to your table and then switch to Datasheet View.
In the Access ribbon, switch to the "Table Tools > Table" tab and click "Before Change"
then enter the following macro ...
... or paste the following XML into the macro editor window
<?xml version="1.0" encoding="utf-16" standalone="no"?>
<DataMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application">
<DataMacro Event="BeforeChange">
<Statements>
<ConditionalBlock>
<If>
<Condition>[IsInsert]</Condition>
<Statements>
<Action Name="SetLocalVar">
<Argument Name="Name">next_seq</Argument>
<Argument Name="Value">1</Argument>
</Action>
<Action Name="SetLocalVar">
<Argument Name="Name">prefix</Argument>
<Argument Name="Value">"SAC" & Year(Date()) Mod 100 & "-"</Argument>
</Action>
<LookUpRecord>
<Data Alias="pd">
<Query>
<References>
<Reference Source="poledata" Alias="pd" />
</References>
<Results>
<Property Source="pd" Name="alternate_id_seq" />
</Results>
<Ordering>
<Order Direction="Descending" Source="pd" Name="alternate_id_seq" />
</Ordering>
</Query>
<WhereCondition>[pd].[alternate_id] Like [prefix] & "*"</WhereCondition>
</Data>
<Statements>
<Action Name="SetLocalVar">
<Argument Name="Name">next_seq</Argument>
<Argument Name="Value">[pd].[alternate_id_seq]+1</Argument>
</Action>
</Statements>
</LookUpRecord>
<Action Name="SetField">
<Argument Name="Field">alternate_id_seq</Argument>
<Argument Name="Value">[next_seq]</Argument>
</Action>
<Action Name="SetField">
<Argument Name="Field">alternate_id</Argument>
<Argument Name="Value">[prefix] & [next_seq]</Argument>
</Action>
</Statements>
</If>
</ConditionalBlock>
</Statements>
</DataMacro>
</DataMacros>
Now when new rows are added to the table the [alternate_id_seq] and [alternate_id] columns will be populated automatically.
I am working on an Access 2013 database that will have different utility poles entered into the database and linked with other attributes. Each pole will have a unique global ID, and to simplify working I would like to add another unique ID that is more simple. I would like this field auto populated when a new pole in imported into the database. The ID would go as follows:
SAC(year)-(Escalating number, cannot be a duplicate)
ex. SAC16-20 (This would be the 20th pole entered into the database in 2016)
ex. SAC15-2536 (Would be the 2536th pole entered in 2015)
If anyone could help me generate some code to make this auto populate ID field work I would greatly appreciate it.
With Access versions 2010 and later you can use an event-driven data macro to generate the sequential ID. For example, say you have a table named [poledata]. Open it in Design View and add two fields:
alternate_id_seq – Numeric (Long Integer)
alternate_id – Text(20)
Save the changes to your table and then switch to Datasheet View.
In the Access ribbon, switch to the "Table Tools > Table" tab and click "Before Change"
then enter the following macro ...
... or paste the following XML into the macro editor window
<?xml version="1.0" encoding="utf-16" standalone="no"?>
<DataMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application">
<DataMacro Event="BeforeChange">
<Statements>
<ConditionalBlock>
<If>
<Condition>[IsInsert]</Condition>
<Statements>
<Action Name="SetLocalVar">
<Argument Name="Name">next_seq</Argument>
<Argument Name="Value">1</Argument>
</Action>
<Action Name="SetLocalVar">
<Argument Name="Name">prefix</Argument>
<Argument Name="Value">"SAC" & Year(Date()) Mod 100 & "-"</Argument>
</Action>
<LookUpRecord>
<Data Alias="pd">
<Query>
<References>
<Reference Source="poledata" Alias="pd" />
</References>
<Results>
<Property Source="pd" Name="alternate_id_seq" />
</Results>
<Ordering>
<Order Direction="Descending" Source="pd" Name="alternate_id_seq" />
</Ordering>
</Query>
<WhereCondition>[pd].[alternate_id] Like [prefix] & "*"</WhereCondition>
</Data>
<Statements>
<Action Name="SetLocalVar">
<Argument Name="Name">next_seq</Argument>
<Argument Name="Value">[pd].[alternate_id_seq]+1</Argument>
</Action>
</Statements>
</LookUpRecord>
<Action Name="SetField">
<Argument Name="Field">alternate_id_seq</Argument>
<Argument Name="Value">[next_seq]</Argument>
</Action>
<Action Name="SetField">
<Argument Name="Field">alternate_id</Argument>
<Argument Name="Value">[prefix] & [next_seq]</Argument>
</Action>
</Statements>
</If>
</ConditionalBlock>
</Statements>
</DataMacro>
</DataMacros>
Now when new rows are added to the table the [alternate_id_seq] and [alternate_id] columns will be populated automatically.
I am working on an Access 2013 database that will have different utility poles entered into the database and linked with other attributes. Each pole will have a unique global ID, and to simplify working I would like to add another unique ID that is more simple. I would like this field auto populated when a new pole in imported into the database. The ID would go as follows:
SAC(year)-(Escalating number, cannot be a duplicate)
ex. SAC16-20 (This would be the 20th pole entered into the database in 2016)
ex. SAC15-2536 (Would be the 2536th pole entered in 2015)
If anyone could help me generate some code to make this auto populate ID field work I would greatly appreciate it.
With Access versions 2010 and later you can use an event-driven data macro to generate the sequential ID. For example, say you have a table named [poledata]. Open it in Design View and add two fields:
alternate_id_seq – Numeric (Long Integer)
alternate_id – Text(20)
Save the changes to your table and then switch to Datasheet View.
In the Access ribbon, switch to the "Table Tools > Table" tab and click "Before Change"
then enter the following macro ...
... or paste the following XML into the macro editor window
<?xml version="1.0" encoding="utf-16" standalone="no"?>
<DataMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application">
<DataMacro Event="BeforeChange">
<Statements>
<ConditionalBlock>
<If>
<Condition>[IsInsert]</Condition>
<Statements>
<Action Name="SetLocalVar">
<Argument Name="Name">next_seq</Argument>
<Argument Name="Value">1</Argument>
</Action>
<Action Name="SetLocalVar">
<Argument Name="Name">prefix</Argument>
<Argument Name="Value">"SAC" & Year(Date()) Mod 100 & "-"</Argument>
</Action>
<LookUpRecord>
<Data Alias="pd">
<Query>
<References>
<Reference Source="poledata" Alias="pd" />
</References>
<Results>
<Property Source="pd" Name="alternate_id_seq" />
</Results>
<Ordering>
<Order Direction="Descending" Source="pd" Name="alternate_id_seq" />
</Ordering>
</Query>
<WhereCondition>[pd].[alternate_id] Like [prefix] & "*"</WhereCondition>
</Data>
<Statements>
<Action Name="SetLocalVar">
<Argument Name="Name">next_seq</Argument>
<Argument Name="Value">[pd].[alternate_id_seq]+1</Argument>
</Action>
</Statements>
</LookUpRecord>
<Action Name="SetField">
<Argument Name="Field">alternate_id_seq</Argument>
<Argument Name="Value">[next_seq]</Argument>
</Action>
<Action Name="SetField">
<Argument Name="Field">alternate_id</Argument>
<Argument Name="Value">[prefix] & [next_seq]</Argument>
</Action>
</Statements>
</If>
</ConditionalBlock>
</Statements>
</DataMacro>
</DataMacros>
Now when new rows are added to the table the [alternate_id_seq] and [alternate_id] columns will be populated automatically.
I'm using atocompleter in my form with json.
This is the part of my struts.xml
<package name="json" namespace="/" extends="json-default">
<result-types>
<result-type name="json" class="com.googlecode.jsonplugin.JSONResult" />
</result-types>
<action name="test" class="testClass" method="populate">
<result type="json" name="success">
<param name="root">itemList</param>
<param name="contentType">text/html</param>
</result>
</action>
</package>
This is the jsp
<s:form id="frm_demo" name="frm_demo" theme="simple" action="test2">
<s:url id="remoteurl" action="test" />
<sj:autocompleter
id="lst"
name="lst"
list="%{remoteurl}"
listValue="name"
listKey="id"
selectBox="true"
/>
<s:submit value="submit"/>
</s:form>
This is the action class method
public String populate() throws Exception{
itemList.put("1", "a");
itemList.put("2", "b");
itemList.put("3", "c");
return "success";
}
With the above code in struts.xml my jsp renders like this.{"3":"c","2":"b","1":"a"}
But when I delete the "contentType" parameter, in other words the content type is "application/json" the jsp pops the download window.
I need theauto completer to return the key when i click submit button. But the page doesn't load with the autocompleter. Any solutions?
p.s. itemList i used in my action class is a HashMap... does that matter?
Using map is OK with collection-backed components. I think there's couple of problems with your code.
First in you action configuration you have set the root object to your itemList, this way only content of the list will be converted to json so you can't refer to the list itself in your autocompleter.
Second you have to set the href attribute for your autocompleter and set the remoteUrl as it's value. So your code could be like:
<package name="json" namespace="/" extends="json-default">
<action name="test" class="testClass" method="populate">
<result type="json"/>
</action>
</package>
In your autompleter:
<s:form id="frm_demo" theme="simple" action="test2">
<s:url id="remoteurl" action="test" />
<sj:autocompleter href="%{remoteurl}"
id="lst"
name="lst"
list="itemList"
listValue="name"
listKey="id"
selectBox="true"/>
<s:submit value="submit"/>
</s:form>
See if that works.
I think your code is ok,Just remove this code
<param name="contentType">text/html</param>