I'm trying to find out what store a page belongs to in Magento. We currently have along these lines:
$cms_pages = Mage::getModel('cms/page')->getCollection();
$cms_pages->load();
foreach($cms_pages as $_page) {
$data = $_page->getData();
}
How would I get the store ID for each page? Ideally I'd like something as simple as $data->store_id(); but I've not found anything of use yet. Can anyone point me in the right direction?
Add Store id to your collection and it will only return the pages you need:
$collection = Mage::getModel('cms/page')->getCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->setOrder('sortorder', 'asc');
Related
I'm building a Laravel 9x application where i will need to populate some pages with the google places API.
Reading at the ToS of Google Places, i can only store in my db, for at most 30 days, the place_id.
Now, I'm facing an issue; I have a restaurants.index blade page where I'm showing in a table all the records from the restaurants table.
The issue is that i need to show in each table row the name of the restaurant that i don't have in my db table but i need to fetch it from Google Places Api.
So far, in my RestaurantsController I have done the following :
public function index()
{
$getAllRecords = Restaurant::all();
$google_places_api = new PlacesApi(env('GOOGLE_MAPS_API_KEY'));
$restaurants = new Collection();
foreach($getAllRecords as $restaurant){
$response= $google_places_api->placeDetails($restaurant->google_place_id);
$restaurant['name'] = $response['result']['name'];
$restaurants->prepend($restaurant);
}
dd($restaurants);//When dd here, the collection shows correctly the added value.
$restaurants->paginate(8);
$categories = Category::where('type', 'Restaurant')->cursor();
return view('tenant.restaurants.index', compact('categories', 'restaurants'));
}
And it seems to work pretty well if I dd($restaurants) inside the RestaurantsController as you can see from the picture below :
But when i try to #dd($restaurants) from the restaurants.index page, the added name is completely disappeared as you can see from the picture below :
It's now about a whole day that I'm tryng to understand why this behavior happen, is there anybody who has an idea of what is happening?
Thank you
I am trying to create a trending or popular list of categories in my application but not sure how it works or if what i have works as it should. In my category table, i added a view_count column. In the php block i have
$viewed = Cat::where('parent_id','>',0)->first();
$viewed->increment('view_count',1);
$viewed->save();
$this['trending'] = Cat::orderBy('view_count', 'desc')->take(10)->get();
How do i correctly do this and add session to it so it does not count with each reload by a user?
Edit: I currently have this looking at how it is done in laravel. Dont know if it works differently with october
public function show(Cat $cat)
{
$id = $cat->id;
$cat = Cat::find($id)->where('parent_id', '>', 0)->increment('view_count');
$this['trending'] = Cat::orderBy('view_count')->take(10)->get();
}
I am assuming you would have category_id on trending category page so your code for incrementing view count must have been
Cat::find($category_id)->increment('view_count');
and that's it.
let me know if you need more help
I'm using Laravels Consoletvs\charts to generate charts for my project. I'm trying to get the chart to only display the "question" created by a specific user, currently it just displays all the "questions" that are in the database, but I'm unsure on how to write the string for this, basically I need it to only show the "question" that match the id of the user that is currently logged in.
Any help is much appreciated :)
My chart controller is shown below
$questions = Question::where(DB::raw("(DATE_FORMAT(created_at,'%Y'))"),date('Y'))
->get();
$questionChart = Charts::database($questions, 'bar', 'highcharts')
->title("Questions Assigned")
->elementLabel("Total Questions")
->dimensions(1000, 500)
->responsive(true)
->groupByMonth(date('Y'), true);
return view('welcome', compact('userChart', 'testChart', 'questionChart'));
}
}
If I'm not wrong then you want to display the questions created by the logged in user.
To get a solution you must have a relation predefined between the questions and users table.
I'm assuming that you have a user_id column in your Question Model
$loggedin_user_id = 'some_id';
Try this
$questions = Question::where('user_id', $loggedin_user_id)
->get();
I am beginner in SocialEngine and I want to know if there is any way to get the photo of the object in the widget.
Like i know we can get the photo of the object in view using following code.
//in controller
$table = Engine_Api::_()->getDbTable("mytable","module");
$select = $table->select()->where->("table_id", 1);
$fetch = $table->fetchRow($select);
$this->view->fetch = $fetch;
//in view
echo $this->itemPhoto($this->fetch, "thumb.normal");
above line would product the image if there is any otherwise will load the default image.
But this line of code is not working in widget.
I really appreciate your help.
You need to make sure that first param you're passing to $this->itemPhoto is a User instance:
$this->itemPhoto($user, 'thumb.normal', $user->getTitle())
Seems that in your case $this->fetch is simply a Row. You can create user using this code: Engine_Api::_()->getItem('user', $user_id);. Hope this helps.
I'm looking for a solution to display posts based on the viewers
location.
For Example: I'm writing an article and set an option so it is only
visible for users from within USA.
If a user in Germany is visiting the Wordpress page, the post does
not appear.
I don't want to change content within a post, but more hide and show
them with an option for the author.
If there is some plugin, that can do this, I would highly appreciate.
Thanks.
I had similar problem. Didn't found a plugin and wrote this to query post for country of visitor: (remember to get your key at http://ipinfodb.com/)
$ip=$_SERVER['REMOTE_ADDR'];
$request = 'http://api.ipinfodb.com/v3/ip-country/?key= get your own key &ip='.$ip.'&format=json';
$response = file_get_contents($request);
$jsonobj = json_decode($response);
if ($jsonobj->countryCode == "SE"){
// args for query post for selected country $args = array ()
}
elseif ($jsonobj->countryCode == "PL"){
// args for query post for selected country $args = array ()
}
query_posts( $args );
Have a look at this discussion over here: https://wordpress.stackexchange.com/questions/26832/display-only-certain-posts-based-on-visitors-country. It might not give you a ready-to-use solution but maybe it helps as a pointer in the right direction.