output of goods ubercart3 - drupal-7

please help to solve the problem.
ubercart3 by default displays the items through views, using the 2-cycle
<?php foreach ($rows as $row_number => $columns): ?>
<?php foreach ($columns as $column_number => $item): ?>
<?php print $item; ?>
<?php endforeach; ?>
<?php endforeach; ?>
I would like to bring goods through one cycle. help please

Related

How to show only 2 post from post in ACF relationship

After creating customfield from ACF. I select multiple articles. How can I show only the last 2 posts? Thank!
Show only 2 post from relationship ACF
I would use the post_object field. With this field, you can select which objects you would like to display, when you configure it to "multiple values".
<?php
$featured_posts = get_field('featured_posts');
if( $featured_posts ) { ?>
<ul>
<?php foreach( $featured_posts as $post ) {
setup_postdata($post); ?>
<li>
<?php the_title(); ?>
</li>
<?php } ?>
</ul>
<?php
wp_reset_postdata(); ?>
<?php } ?>

Cakephp foreach

When I use foreach to show the my value in the base it show me a false value
in the controller:
public function index_hote() {
$this->Reservation->recursive = 1;
$this->loadModel("Bien");
$biens=$this->Bien->find('first',array('conditions'=>array("Bien.idBien =idBien")));
$reservations=$this->Reservation- >find('first',
array('conditions'=>array('Reservation.idBien'=> $biens['Bien'] ['idBien'])));
Debugger::dump($reservations['Reservation']);
$this->paginate('Reservation');
$this->set('reservations', $reservations['Reservation']);
}
In the view:
<?php foreach ($reservations as $reservation): ?>
<tr>
<?php echo h($reservation) ?>
<td><?php echo h($reservation['dateReserDu']); ?> </td>
<td><?php echo h($reservation['dateReserAu']); ?> </td>
<td><?php echo h($reservation['montantAPaye']); ?> </td>
<td><?php echo h($reservation['etatReservation']); ?> </td>
</tr>
<?php endforeach; ?>
When I debug it shows me the right value (the pic after doing Debugger::dump($reservations['Reservation']);):
but in the table it shows me a false value:
When I do <?php echo h($reservation) ?> it shows me the right value but when I add a attribute such as h($reservation['dateReserDu']); ?> it doesn't work PLZ why? And when can I do?
Why you are using loop here ? You have used find('first') to retrieve one data see
doc .
If you want to retrieve all data use find('all'). However if you want to echo your find 1st data just use below structure
$this->set('reservations', $reservations);
In view
echo $reservations['Reservation']['Your_field_name'];

ACF Relationship Field posts per page

I'm using Advanced Custom Fields to call my related posts, which is all working fine, but how can I adapt this code to only call 3 posts at random?
Thank you for any help in advance!
<?php
$posts = get_field('associate_adverts');
if( $posts ): ?>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<img src="<?php the_field('advert'); ?>">
<?php endforeach; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
I associated it the opposite way in the end and this solution worked..
<?php
$adverts = get_posts(array(
'post_type' => 'adverts',
'posts_per_page' => '3',
'meta_query' => array(
array(
'key' => 'associate_adverts', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
));
?>
<?php if( $adverts ): ?>
<?php foreach( $adverts as $advert ): ?>
<?php $photo = get_field('advert', $advert->ID); ?>
<img src="<?php echo $photo['url']; ?>"/>
<?php endforeach; ?>
<?php endif; ?>

Advanced Custom Fields: checkbox in repeater field

I can’t seem to get checkboxes working in an Advanced Custom Fields repeater field. The goal is that a different image will be spit out based on what checkbox has been ticked off. The time/title/description part is working great... just need some assistance understanding how to work in the checkbox values.
<?php if( have_rows('agenda') ): ?>
<ul>
<?php while( have_rows('agenda') ): the_row();
$time = get_sub_field('time');
$title = get_sub_field('title');
$description = get_sub_field('description');
$image = get_sub_field('imagepicker');
?>
<li>
<h3><?php echo $time; ?><?php echo $title; ?></h3>
<?php if( $description ): ?>
<?php echo $description; ?>
<?php endif; ?>
<?php if ( 'option1' == get_sub_field('imagepicker') ): ?>
<img src="/option1.jpg" />
<?php elseif ( 'option2' == get_sub_field('imagepicker') ): ?>
<img src="/option2.jpg" />
<?php elseif ( 'option3' == get_sub_field('imagepicker') ): ?>
<img src="/option3.jpg" />
<?php else: ?>
<?php endif; ?>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
(and yes I have gone over the other similar S.O. answers but no luck)
finally figured it out... working snippet below in case anyone else runs into the same thing.
<?php if ($image[0] == 'option1') : ?>
<img src="/option1.jpg" />
<?php elseif ($image[0] == 'option2') : ?>
<img src="/option2.jpg" />
<?php elseif ($image[0] == 'option3') : ?>
<img src="/option3.jpg" />
<?php endif; ?>

Saving current view id 14 in /localhost/topp/events/view/14 to comments table field

Trying to save the current event id '14' in the url '/localhost/topp/events/view/14' to a event_id field in a comments table. I am using the add function in the comments controller and an 'add comment' button on the events view.ctp page. Any ideas? I have been advised to use a hidden id field and $this->params['pass']['0'] but not sure how to go about this, any advice is welcome. Thanks in advance.
My current comments controller add action code:
public function add() {
//$this->loadModel('Event');
if ($this->request->is('post')) {
$this->Comment->create();
$this->request->data['Comment']['user_id'] = $this->Auth->user('id');
//Commented below is the logic Iam trying to achieve but is wrong
//$this->request->data['Comment']['event_id'] = $this->request->data['Event']['id'];
if ($this->Comment->save($this->request->data)) {
$this->Session->setFlash(__('The comment has been saved'));
$this->redirect(array('controller' => 'events', 'action' => 'myevents'));
} else {
$this->Session->setFlash(__('The comment could not be saved. Please, try again.'));
}
}
}
//////////////////////////////////////// My Events View code with add comment link//////////////////////////
<div class="events view">
<?php echo $this->element('maintitle'); ?>
<?php echo $this->element('profile_area'); ?>
<h2><?php echo __('Event'); ?></h2>
<dl>
<td><?php echo $this->Html->image('/files/event/photo/'.$event['Event']['id'].'/thumb_'.$event['Event']['photo'], array("alt" => "No Event Image")); ?> </td>
<td><?php echo $this->Html->image('/files/event/photo2/'.$event['Event']['id'].'/thumb_'.$event['Event']['photo2'], array("alt" => "No Event Image")); ?> </td>
<td><?php echo $this->Html->image('/files/event/photo3/'.$event['Event']['id'].'/thumb_'.$event['Event']['photo3'], array("alt" => "No Event Image")); ?> </td>
<td><?php echo $this->Html->image('/files/event/photo4/'.$event['Event']['id'].'/thumb_'.$event['Event']['photo4'], array("alt" => "No Event Image")); ?> </td>
<dt></dt>
<dd>
<br>
</dd>
<dt><?php echo __('Name'); ?></dt>
<dd>
<?php echo h($event['Event']['name']); ?>
</dd>
<dt><?php echo __('Date'); ?></dt>
<dd>
<?php echo h($event['Event']['date']); ?>
</dd>
</dl>
</div>
<div class="related">
<h3><?php echo __('Related Comments'); ?></h3>
<?php if (!empty($event['Comment'])): ?>
<?php echo ('Add a comment for this event') ?>
<?php
$i = 0;
foreach ($event['Comment'] as $comment): ?>
<tr>
<td><?php echo $comment['comment']; ?></td>
<td class="actions">
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
<div class="actions">
<ul>
<li><?php echo $this->Html->link(__('New Comment'), array('controller' => 'comments', 'action' => 'add')); ?> </li>
</ul>
</div>
</div>
Let me see if I got this right.
The form you posted is in the event view
The link "New Comment" redirects to another view "add", in the comments controller
This add view has a form to actually write a comment (I'm guessing this part,
you didn't put that code here)
You want the add function to have the event_id from where this came from.
Right?
You then need to pass the id of the event from event_view.ctp (I'm inventing names here) to comment_add.ctp.
So two ways to do it
First way: pass the id of the event in the link and recieve it in the action like this
//event_view.ctp
//I'm going to assume you know the event id here
$this->Html->link(__('New Comment'), array('controller' => 'comments', 'action' => 'add', $event_id)); ?>
That will create a link like comments/add/14, for example, where 14 is the event id. Now in the action, you receive the id
//pass it like parameter of the action
public function add($event_id = null) {
if ($this->request->is('post')) {
$this->Comment->create();
$this->request->data['Comment']['user_id'] = $this->Auth->user('id');
//check that the event_id isn't null and that the event actually exists first
$this->request->data['Comment']['event_id'] = $event_id;
/*etc*/
}
}
You don't need to pass the event_id to the comment_add view, if the user doesn't need to handle it, there's no need to add it to the form.
Second way: If you don't want to pass the event_id inside the url, you need to pass is by POST. To do that, the link you now have to add new comments needs to change to a form with the event_id hidden.
echo $this->Form->create('Comment', array('url'=>array('controller' => 'comments', 'action' => 'add')));
echo $this->Form->input('event_id', array('type'=>'hidden', 'value'=>$event_id);
echo $this->Form->end('New comment');
//instead of <?php echo $this->Html->link(__('New Comment'), array('controller' => 'comments', 'action' => 'add')); ?>
And in the action of the comments, check if the post you receive contains event_id, but not user_id, for example. I find this way a bit messy because every request you receive for that action is going to be a post, so it's be harder to differentiate when you want to display the form to be filled, and when you want to save it.
I like the first way better, and I recommend doing that. But I felt the need to point out there are other ways to do it. Depends what you want.

Resources