I'm currently working on a gallery system using cakephp. In it, we have paginated each image album so each page contains a set number of images at most. I have attained this by using:
$this->paginate = array(
'conditions' => array(
'Item.album_id' => $id
),
'order' => array(
'Item.added' => 'desc'
),
'limit' => '50'
);
On my view controller. With this, I can show all the items on each page with no problems.
I'm currently, however, facing a single issue: I need to show, after all the items in the current page, a button that leads to the next page. This is not a problem, except that by design the button that says NEXT PAGE should have an item from the next page as its background.
I have looked around, trying to figure out a way to pull an item from the next page of a paginated system in cakephp without luck. Has anyone done this, or does anyone have a clue how to go about it?
You have to query the preview image manually in the current page.
To access the page number you can use $this->params in the action. Then you have to query images with 'limit' and 'page' parameters as mentioned in the documentation.
After that set the image URL like this:
$this->set('preview_image_url', $queried_url);
Then in the view use inline styling to set the background for the next button.
With Alto's help, I ended up doing this (Putting it here just in case anyone wonders exactly how I did it):
$CurrPage = $this->params['paging']['Item']['page'];
$NextParams = array(
'limit' => 1,
//'page' => $CurrPage + 1,
'order' => array(
'Item.added' => 'desc'
),
'offset' => $CurrPage*50
//'order' =>('rand()')
);
$NextImage = $this->Item->find('first', $NextParams);
$this->set('NextImage', $NextImage);
This gives me the first item from the following page, which is good enough for me. Note the commented 'order' =>('rand()') - I tried to grab a random item from the following page but, alas, it seems like Cake first scrambles all items and THEN paginates. There's probably a way around this, but for now this one did it for me.
Also, using 'page' => $CurrPage + 1 didn't seem to work, with the system instead returning a seemingly randomly chosen image. That's why I instead defaulted to using 'offset' => $CurrPage*50, where 50 is the amount of items per page I'm showing.
Related
I am facing a problem to add such a product to the cart.
I manage to create the booking with:
$new_booking = get_wc_booking ($new_booking_data);
$new_booking -> create ($status);
But then I tried to apply these different methods without success:
add_cart_item_data ($cart_item_meta, $product_id); // error 500
or
$ new_booking_object -> add_cart_item ($cart_item_meta); // error 500
The $cart_item_meta object I create is like the following (some keys are duplicative, like for example start and start_date, because I observed in the code that both names are used, and I wanted to be sure to send at least the correct one ;-) ). BTW, by comparing with standard bookings created via the plugin form, I can be sure that the values I set in the array have the correct format.
$cart_item_meta = array(
'all_day' => false,
'cost' => $price,
'customer_id' => 1,
'user_id' => 1,
'date_created' => '',
'date_modified' => '',
'end' => $endDate,
'end_date' => $endDate,
'google_calendar_event_id' => 0,
'order_id' => $order->get_id(),
'order_item_id' => 0,
'parent_id' => 0,
'person_counts' => array($addPaxId => $pax),
'persons' => array($addPaxId => $pax),
'product_id' => $prodId,
'resource_id' => $resourceId,
'start' => $startDate,
'start_date' => $startDate,
'status' => 'in-cart',
'local_timezone' => 'Europe/Brussels',
);
I do get a record in the "posts" table, with the same specifics as a normal booking created by the normal way. In particular, I get post_type = wc_booking, and post_status = in-cart. But the cart remains empty.
I have compared all the entries in the database, and I can't see what is missing. But I'm definitely missing some of the understanding of the mechanics of WooCommerce ...
Does someone can help me to find a way to pass the final step: putting the created booking in the cart ? Thanks!
Well, maybe someone will be interested to know how I worked around, as so far I couldn't find a complete programming solution.
The products I want to book programmatically and add to the cart are existing products in my WooCommerce store. My purpose is just to use my own form to allow the customer to better understand what he books (I'm managing a flight simulators center with several machines), and the native WC Bookings form is not clear enough for me, and moreover it is really heavy and slow.
So after gathering customers info with my own form (simulator, duration, participants, timeslot), my problem was to put all this in the cart. I could achieve to create the relevant booking in the database, but not add it to the cart.
I observed that when you book via the standard form, you send a POST to the server on the same product page, including the following parameters (random data for example):
wc_bookings_field_persons_xxxx => 2 // 'xxxx' is the ID of the related 'bookable_person' in 'posts'
wc_bookings_field_start_date_month => 11 // November (sample)
wc_bookings_field_start_date_day => 26 // the 26th (sample)
wc_bookings_field_start_date_year => 2021 // Year (sample)
wc_bookings_field_start_date_time => 2021-11-26T15:00:00+0100
wc_bookings_field_start_date_local_timezone => Europe/Brussels
add-to-cart => 1147 // the product ID in 'posts'
So the simplest solution is to create a POST call (via form + button or button + ajax), setting the action/ajax url to the related product after filling the fields here above with the custom form...
EDIT: while I was thinking this was the solution, I discovered that it worked only when another tab in my browser previously 'opened the door' by adding the same product in the standard way. But when this tab is closed (or timeout), the above method fails and just open the product page. The 302 redirect that was operating stops to work for un unknown reason, and we get the standard 200 straight forward. No Cart.
So the question is still pending.
I need to add variations to my Woocommerce products programmatically and I borrowed the code from this answer thread:
Create programmatically a WooCommerce product variation with new attribute values
It works, but gives me two variations when I pass this data array:
$variation_data = array(
'attributes' => array(
'kidssize' => '2'
),
'sku' => '',
'regular_price' => '120',
'sale_price' => '',
'stock_qty' => '',
);
My guess is that funcntion fires two times.
Since i am a noob in php and backend in general all I know how to call a function is from some template file and visiting the page.
And to prevent other visitors from triggering it I use
if(isset($_GET['**parameter Only I know**']))
… wrap and call it going to the page with set parameter;
I understand that this is a really bad way for doing that, but how do I do it otherwise if I need to call function once and never use it again?
And is even firing twice a problem here or is it something wrong with my array?
EDIT:
Here's a detailed process of what i do:
i put the function from the link above in functions.php,
then put the call in footer.php of my theme with above mentioned wrap (the parameter is irrelevant - it could be anything, because it's just used as a trigger)
and go to the page with said parameter to trigger the call,
load the page only once and look for the result in admin panel.
And it has 2 variations always, even if i add more attributes to an array it will return 2 variatons of the last attributes array item;
I am using mediaelement.js to play Audio in my Wordpress site. I'm having trouble getting it to function exactly like the player on the front page of the mediaelementjs site. Particularly, I want to add timestamps when the user hovers over the audio player so that they can more easily navigate to a particular time. The player is working fine otherwise.
A second, related question. Has anyone found an easy way to add links to particular time stamps in this player (e.g. clicking 1:00 would cause the video to jump to that place without reloading the page). I tried the plugin "Skip to timestamp" but could not get the shortcodes to execute properly within my PHP template.
Sorry I don't have any code up live yet. Here is the code to generate the player.
$attr = array(
'src' => 'myfilepath',
'loop' => '',
'autoplay' => '',
'preload' => 'none',
'features' => array('playpause','progress','current','duration','volume')
);
echo wp_audio_shortcode( $attr );
The categories have:
The "top" option marked already
They're assigned to a store
They're assigned to a manufacturer
And they're still not being shown. I don't think this is a code issue as it was working just fine with the default products/categories and I haven't touched the code yet.
I've researched a lot, but people always say that marking the "Top" option should solve the issue.
Please take a look into the below screenshots.
http://postimg.org/image/yv6p186kf/
http://postimg.org/image/wcl00jku7/
postimg.org/image/pbx07rj27
Thanks
Edit:
I'm using OpenCart v1.5.6
Edit 2:
It is a parent category.
For those who are still researching this, please read my answer.
It seems to be an OpenCart bug.
Here is what I've done to fix the issue:
Instead of leaving the "Parent" field as blank, try to type a invalid name in the field so it will show the -- None -- option, select it and click on save. It solved the problem in my case.
Please see the screen shot.
http://i.stack.imgur.com/WWPBY.png
Do the following steps:
Open and edit your category:
In tab Data:
Find and Check:
Top: Display in the top menu bar. Only works for the top parent
categories.
I was not getting the child categories in the form field so I did this.
Create the category without parent
Add this category to the products that you want.
Now edit the category and add the parent to it.
The component is written to return just 5 top results, the issue arises after there is a categories overload
to Fix the issue goto file
/admin/controller/catalog/category.php
function autocomplete()
{
$json = array();
if (isset($this->request->get['filter_name']))
{
$this->load->model('catalog/category');
$filter_data = array(
'filter_name' => $this->request->get['filter_name'],
'sort' => 'name',
'order' => 'ASC',
'start' => 0,
'limit' => 5
);
$results = $this->model_catalog_category->getCategories($filter_data);
foreach($results as $result)
{
$json[] = array(
'category_id' => $result['category_id'],
'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
);
}
}
$sort_order = array();
foreach($json as $key => $value)
{
$sort_order[$key] = $value['name'];
}
array_multisort($sort_order, SORT_ASC, $json);
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
and change limit from 5 to a higher number, preferably 20 in
$filter_data = array(
'filter_name' => $this->request->get['filter_name'],
'sort' => 'name',
'order' => 'ASC',
'start' => 0,
'limit' => 20
);
Here is the issue I ran into. When you are in the admin area and trying to select the category that your product belongs to... Make sure you fully click. I dont have a mouse, so if you have a mouse or trackball this may not address your issue. My Asus Laptop finger pad allows me to lightly tap or fully click the pad to navigate. I had to make sure I clicked my category choices. If I only tapped the pad lightly it pretended to make a selection and the category would not register. So my issue was probably related to a javascript/hardware quirk.
Wasted an hour with that one.... LOL.
Hope this helps someone else. I am using Opencart version 3.0.3.8
The powers that be at stack exchange may not have the same hardware as me or some of us. Please dont flag this post because you don't understand this post. This will help someone else. These people think they know everything. And probably filter out some good answers.
I am currenty working on a story board, and i upload images there telling a story.
So the problem is i just want to limit the related query.
The story board has a has_manyrelation for images. and on the list where the story boards appear i just only want to show the first image, and when someone clicks it it will show all, the show all is fine, but i can limit just the related images in my view.
And im totally confused with it because i read lot of infos about it in the forum, tried may variations, the limit is just ignored, or i get errors
so here is my code
controller
$stories = Model_Storyboard::find('all', array('related' => array('storyboardimage')));
$this->template->title = "Sotry Board | " . Config::get('site_name');
$this->template->content = View::forge('storyboard/index', array('stories' => $stories));
So how can i limit the storyboardimage to show the first image for each storyboard?
Sorry if im askin to much, but i would be really happy if someone could give me a working example beacuse i tried lots of variations and nothing works...
You can add criteria onto the relations, i.e. where, order_by, limit etc.
For example (note this is untested)
$stories = Model_Storyboard::find('all', array(
'related' => array(
'storyboardimage' => array(
'limit' => 1,
'order_by' => array(
'field_indicative_of_first_image' => 'desc'
),
)
)
));
In the example above I've added in field_indicative_of_first_image which simply means replace this with a column which you can use to get the first image. This might be for example a created_at column or a weight or sort_order column. Without knowing your database schema, I can't tell you which you'd need.