Separate woocommerce variable products on archive page - variables

Is there a way to show woocommerce product variations separately on the product category, search or another archive page? For example, if there are red t-shirt and yellow t-shirt variations it should display 2 products on 't-shirt' search result page.
Thanks.

Try this code..
<?php
/**
* woocommerce_after_shop_loop_item_title hook
*
* #hooked woocommerce_template_loop_rating - 5
* #hooked woocommerce_template_loop_price - 10
*/
do_action( 'woocommerce_after_shop_loop_item_title' );
?>
</a>
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
with this:
<?php
/**
* ADD PRODUCT VARIABLE WITH ADD TO CART ON CATALOG PAGE
ADDED BY GW
**/
?>
<div class="catbox">
<?php
//ADD SHORT DESCRIPTION TO PRODUCT
add_action('woocommerce_after_shop_loop_item_title','woocommerce_template_single_excerpt', 5); ?>
do_action( 'woocommerce_after_shop_loop_item_title' );
?>
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
<?php
//ADD VARIATIONS BEFORE ADD TO CART
if($product->product_type == "variable"){
woocommerce_variable_add_to_cart();
} else {
woocommerce_template_loop_add_to_cart();
}
?>

Related

Magento 2 : How to display customer email on checkout success page?

My code is given below
app/code/custom/checkout/block/success.php
class Success extends \Magento\Checkout\Block\Onepage\Success
{
public function getOrder()
{
$order = $this->_checkoutSession->getLastRealOrder();
return $order;
}
app/design/frontend/vendor/themename/Magento_Checkout/layout/checkout_onepage_success.xml
<referenceContainer name="content">
<block class="Custom\Checkout\Block\Success" name="checkout.success" template="Magento_Checkout::success.phtml" cacheable="false">
<container name="order.success.additional.info" label="Order Success Additional Info"/>
</block>
</referenceContainer>
app/design/frontend/vendor/themename/Magento_Checkout/templates/success.phtml
<?php if($block->getOrderId):?>
<div class="success-title" data-bind="i18n: 'Thank you for your purchase!'" data-role="title">
<h2><?= __('Thank you for your purchase!');?></h2>
</div>
<p><?= __('Your payment has been received. A confirmation of your order has been sent to ');?><?php echo '"'.$block->getOrder()->getCustomerEmail().'"'?></p>
<?php if ($block->getCanViewOrder()) :?>
<p class="successmessge"><?= __('Your order number is: %1.', sprintf('<strong>%s</strong>', $block->escapeHtml($block->getViewOrderUrl()), $block->escapeHtml($block->getOrderId()))) ?></p>
<?php else :?>
<p class="successmessge"><?= __('Your order number is: <span>%1</span>.', $block->escapeHtml($block->getOrderId())) ?></p>
<?php endif;?>
<p><?= /* #escapeNotVerified */ __('Check your inbox for estimated delivery time') ?></p>
<p><?= /* #escapeNotVerified */ __('If you have any questions regarding your order , please contact our customer service department on contact#cii.co.uk or +44(0)12 3456 7891') ?></p>
<?php endif;?>
$block->getOrder()->getCustomerEmail();
this is returning error : call to non-member function is null
app/code/Custom/Checkout/etc/frontend/di.xml
<preference for="Custom\Checkout\Block\Success" type="Magento\Checkout\Block\Onepage\Success" />
All the things are working well.
but not getting block to success page
Please help me what is wrong in my code?

get value of CHtml::activeDropDownList in yii

I have this code
<?php echo CHtml::activeDropDownList(
$semaineModel,
'libelleSemaine',
CHtml::listData(Semaine::findBySql('SELECT * FROM Semaine')->all(), 'idSemine', 'libelleSemaine')
); ?>
but why that displays just the last element of the table, and me I have 6 items in this table 'Semaine 1' to 'Semaine 6'
and that code display just 'Semaine 6'.
an idea please ?
Then you don't nedd CHtml but active dropDownList
Assiming your Semain model is named Semain
use app\models\Semaine;
use yii\helpers\ArrayHelper;
$semaines=Semaine::find()->all();
$listSemaines = $listData=ArrayHelper::map($semaines,'idSemine', 'libelleSemaine');
echo $form->field($model, 'idSemaine')->dropDownList( $listSemaines,
['prompt'=>'Select Semaine...']);

Making new variable for drupal 7 theme showing error notice

Hi I am trying to make a new variable for drupal 7 theme. My theme name is ntheme. For this I have defined a function in template.php :
function ntheme_gnu_preprocess(&$variables)
{
$variables['disclaimer'] = t('Comments are unaythorized. The views expressed are those of the comment author.');
}
And used this variable $disclaimer in comment-wrapper.tpl.php:
<div id="comments" class="<?php print $classes; ?>"<?php print $attributes; ?>>
<?php if ($content['comments'] && $node->type != 'forum'): ?>
<?php print render($title_prefix); ?>
<h2 class="title"><?php print t('Comments'); ?></h2>
<?php print render($title_suffix); ?>
<?php endif; ?>
<?php print render($content['comments']); ?>
<?php if ($content['comment_form']): ?>
<h2 class="title comment-form"><?php print t('Add new comment'); ?></h2>
<?php print render($content['comment_form']); ?>
<?php endif; ?>
<p><?php print $disclaimer; ?></p>
</div>
But it showing Notice :
Notice: Undefined variable: disclaimer in include() (line 39 of
C:\wamp\www\drupal\sites\all\themes\ntheme\templates\comment-wrapper.tpl.php).
Whats wrong I am doing ?
Is your theme name ntheme_gnu or ntheme beacuse if ur theme name is ntheme u should call the hook_preprocess as ntheme_preprocess()

virtuemart 2 product pdf does not display custom fields

I'm using VirtueMart 2.0.10 with Joomla! 2.5.6 and my problem is the autogenerated pdf documents for each product don't include my custom fields. I'm no php expert but I think theese lines in file /components/com_virtuemart/views/productdetails/tmpl/default_pdf.php has something to do with it, starting at line 145:
<?php // Product custom_fields TODO relation to Childs
if (!empty($this->product->customfields)) { ?>
<div class="product-fields">
<?php
$custom_title = null ;
foreach ($this->product->customfields as $field){
?><div style="display:inline-block;" class="product-field product-field-type-<?php echo $field->field_type ?>">
<?php if ($field->custom_title != $custom_title) { ?>
<span class="product-fields-title" ><strong><?php echo JText::_($field->custom_title); ?></strong></span>
<?php //echo JHTML::tooltip($field->custom_tip, $field->custom_title, 'tooltip.png');
} ?>
<span class="product-field-display"><?php echo $field->display ?></span>
<span class="product-field-desc"><?php echo jText::_($field->custom_field_desc) ?></span>
</div>
<?php
$custom_title = $field->custom_title;
} ?>
</div>
<?php
} // Product custom_fields END ?>
I tested adding an else statement echoing some text after the above if statement and it executetd. So apperently there are no custom fields... but there really are...
I haven't found anyone else experiencing this problem wich I think is weird, but I don't think I have screwed something up. I HAVE made a few changes in the /components/com_virtuemart/views/productdetails/tmpl/default.php file.
I removed all the code that I entered in my question and replaced it with the following code from the file /components/com_virtuemart/views/productdetails/tmpl/default.php:
<?php
$custom_title = null;
foreach ($this->product->customfieldsSorted['normal'] as $field) { // I set the position to normal
if ( $field->is_hidden )
continue;
if ($field->display) {
?>
<?php if ($field->custom_title != $custom_title) { ?>
<b><?php echo JText::_($field->custom_title); ?></b><br />
<?php
if ($field->custom_tip)
echo JHTML::tooltip($field->custom_tip, JText::_($field->custom_title), 'tooltip.png');
}
?>
<?php echo $field->display ?><br />
<?php echo jText::_($field->custom_field_desc) ?><br />
<?php
$custom_title = $field->custom_title;
}
}
?>
I'm no expert but this worked for me. The PDF now includes the custom fields.
As you see in the comment in the code I changed the position to 'normal'. The other positions seems to be 'ontop' and 'onbot'. But I won't change that setting so I leave it be.
EDIT: I forgot to mention I added some other html-code to that segment, like <br /> and <b> just for apperences. So nothing major, just to clarify that the code isn't EXACTLY like it is in the file default.php

How do I select and display a specific field from may table in cakephp?

I have this code in my products_controller.php:
<?php
class ProductsController extends AppController{
var $name = 'Products';
var $helpers = array('Form');
//var $scaffold;
function index(){
$this->Product->recursive = 1;
$products = $this->Product->find('all');
$this->set('products',$products);
//pr($products);
}
function add(){
if(!empty($this->data)){
$this->Product->create();
$this->Product->save($this->data);
$this->redirect(array('action'=>'index'));
}
$categories = $this->Product->Category->find('list',array(
'field'=>array('Category.categoryName')
));
$this->set('categories',$categories);
pr($categories);
}
}
?>
what it actually does in my database is this:
SELECT `Category`.`id` FROM `categories` AS `Category` WHERE 1 = 1
The thing is, I am not trying to select Category.id. I want to select Category.categoryName which is another field in my database so that it will automatically populate a dropdown list in my add.ctp file which goes like this:
<h2>ADD</h2>
<?php echo $form->create('Product'); ?>
<?php
echo $form->input('ProductName');
echo $form->input('categories');
echo $form->end('DONE');
?>
any help would be highly appreciated.
In your Category Model set the displayField Name property with the Category Name.
public $displayField = 'categoryName';