Need help with Wishlist - magento

The wishlist section in the sidebar disappears when all the items in it are removed.. but i want to shot it even when there is no items in wishlist with a text "Add some items to your wishlist".. as like "Compare section".. how do i do it?
i tried editing the .phtml file for doing it, but its not working.. do i need to edit any xml layout file for this?

For just info, please don't reputate.
The wishlist class has been changed after 1.4.2 :
* #deprecated after 1.4.2.0
* #see Mage_Wishlist_Block_Links::__construct
*
* #return array
*/
public function addWishlistLink()
{
return $this;
}
and here is the your requested feature ( look at count ) :
/**
* Add link on wishlist page in parent block
*
* #return Mage_Wishlist_Block_Links
*/
public function addWishlistLink()
{
$parentBlock = $this->getParentBlock();
if ($parentBlock && $this->helper('wishlist')->isAllow()) {
$count = $this->helper('wishlist')->getItemCount();
if ($count > 1) {
$text = $this->__('My Wishlist (%d items)', $count);
}
else if ($count == 1) {
$text = $this->__('My Wishlist (%d item)', $count);
}
else {
$text = $this->__('My Wishlist');
}
$parentBlock->addLink($text, 'wishlist', $text, true, array(), 30, null, 'class="top-link-wishlist"');
}
return $this;
}

Magento 1.6.1.0
/app/code/core/Mage/Wishlist/Block/Customer/Sidebar.php
contains the function _toHtml():
protected function _toHtml()
{
if (($this->getCustomWishlist() && $this->getItemCount()) || $this->hasWishlistItems()) {
return parent::_toHtml();
}
return '';
}
Copy:
/app/code/core/Mage/Wishlist/Block/Customer/Sidebar.php
to:
/app/code/local/Mage/Wishlist/Block/Customer/Sidebar.php
In the copied file, replace the contents of function _toHtml() with return parent::_toHtml();:
protected function _toHtml()
{
return parent::_toHtml();
}

Related

JOOMLA 3.x How to hide a template after if check

I'm trying to understand Joomla language and I have this situation:
In a models/calcoloonline.php I have this function
public function estraivariabili()
{
$db = JFactory::getDBO();
// Put the result into a variable first, then return it.
$value = $db->setQuery("SELECT * FROM #__calcolo_imposte")->loadObjectList();
if ($value != NULL)
{
return $value;
}
else
{
return JFactory::getApplication()->enqueueMessage(JText::_('COM_CALCOLO_IMPOSTE_IMPORTI_NON_DEFINITI'), 'type');
}
}
This works perfectly but I'd like that after check if the return is NULL I want to hide display default.php and show only the message on JText.
How can I do this?
For your purpose, you just return the $value from the model function and call the function at view.html.php's display() function.
At default.php file check the availability of the $value and show your contents.
For example, you store the data at view.php.html. It looks like
public function display($tpl = null)
{
$model = $this->getModel();
$this->value = $model->estraivariabili();
return parent::display($tpl);
}
And your default.php file would be
<?php if (!empty($this->value)) { ?>
<h1>The value is not empty.</h1>
<?php } else {
// value not found :(
JFactory::getApplication()->enqueueMessage(JText::_('NOT_FOUND_MESSAGE'), 'warning');
} ?>

Magento 2 cancel order from myaccount page

Cancelling order in magento 2 programatically:
I implemented the module in magento 1 in which I will cancel the pending order from customer my account page.
Please refer to the code below which I implemented in the magento 1:
$order = Mage::getModel('sales/order')->load($orderId);
$order_status=$order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true)->save();
I want to implement the same functionality in magento 2. Does anyone know how to implement it?
I loaded the order with order id in magento 2, but am unable to cancel the order.
You should use API (more about magento2 API concepts) for that, example how to use it in your class:
<?php
use Magento\Sales\Api\OrderManagementInterface;
class A
{
/**
* #var OrderManagementInterface
*/
private $orderManagement;
/**
* #param OrderManagementInterface $orderManagement
*/
public function __construct(OrderManagementInterface $orderManagement)
{
$this->orderManagement = $orderManagement;
}
public function cancelOrderOne()
{
$orderId = 1;
$isCanceled = $this->orderManagement->cancel($orderId);
}
}
Please look at the code below, it will also validate the user associations for the order also
<?php
Nmaespace\Modulename\Controller\Action;
class Cancelorder extends \Magento\Framework\App\Action\Action
{
protected $orderManagement;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Sales\Api\OrderManagementInterface $orderManagement
) {
$this->orderManagement = $orderManagement;
parent::__construct($context);
}
public function execute()
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
if(!$customerSession->isLoggedIn()) {
$this->_redirect('/');
die;
}
/*get request params */
$get_customer_id = $customerSession->getCustomer()->getId();
$get_order_id = $this->getRequest()->getParam('order_id');
/*get request params */
//die;
$order = $objectManager->create('Magento\Sales\Model\Order')->load($get_order_id);
$getcustomerid = $get_customer_id;
$orderdata = $order->getData();
$order_status = $orderdata["status"];
//print_r($orderdata);
$cus_id = $orderdata["customer_id"];
if($getcustomerid != $cus_id){
echo "We cant Cancel this order at this time" ;
//die("go back");
}
if($order_status == "pending"){
$this->orderManagement->cancel($get_order_id);
echo "Order Cancelled successfully" ;
}
else{
echo "We cant Cancel this order at this time" ;
}
}
}

Magento: Add custom text at the bottom of invoice pdf

I am very new in Magento.
I want to add some "term & condition" at the bottom of customer invoice.
I know This question is already posted on the portal, But I didn't found any solution yet.
Can anyone explain me how to do that.
Open the file app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php and add the below function at the end of the file
public function insertConditions($page)
{
$page->drawLine(25, $this->y, 570, $this->y);
$this->y -= 25;
$page->drawText(Mage::helper('sales')->__('Your custom text here!'), 35, $this->y, 'UTF-8');
}
Now, you need to call this insertConditions() function in the getPdf() function like below :
public function getPdf($invoices = array())
{
$this->_beforeGetPdf();
$this->_initRenderer('invoice');
$pdf = new Zend_Pdf();
$this->_setPdf($pdf);
$style = new Zend_Pdf_Style();
$this->_setFontBold($style, 10);
foreach ($invoices as $invoice) {
if ($invoice->getStoreId()) {
Mage::app()->getLocale()->emulate($invoice->getStoreId());
Mage::app()->setCurrentStore($invoice->getStoreId());
}
$page = $this->newPage();
$order = $invoice->getOrder();
/* Add image */
$this->insertLogo($page, $invoice->getStore());
/* Add address */
$this->insertAddress($page, $invoice->getStore());
/* Add head */
$this->insertOrder(
$page,
$order,
Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId())
);
/* Add document text and number */
$this->insertDocumentNumber(
$page,
Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId()
);
/* Add table */
$this->_drawHeader($page);
/* Add body */
foreach ($invoice->getAllItems() as $item){
if ($item->getOrderItem()->getParentItem()) {
continue;
}
/* Draw item */
$this->_drawItem($item, $page, $order);
$page = end($pdf->pages);
}
/* Add totals */
$this->insertTotals($page, $invoice);
if ($invoice->getStoreId()) {
Mage::app()->getLocale()->revert();
}
}
$this->insertConditions($page); // the custom text is added here
$this->_afterGetPdf();
return $pdf;
}
PS. I would advice to override the core files instead of changing them directly.

get the values of custom options

I'm trying to alter a price based on some custom options set. Therefore I'm trying to get the value a customer has entered, not the default values set in the backend. To do this I'm using the event catalog_product_get_final_price used in Mage_Bundle_Model_Product_Price. I have registered the following observer:
public function observer_callback($evt_obs)
{
$event = $evt_obs->getEvent();
$data = $event->getData();
/* #var $collection Mage_Catalog_Model_Resource_Product_Collection */
$collection = $data['collection'];
$items = $collection->getItems();
/* #var $item Mage_Catalog_Model_Product */
foreach ($items as $item) {
if ( $item->getName() == 'Bundel Test2') {
$options = $item->getCustomOptions();
/* #var $option Mage_Catalog_Model_Product_Option */
foreach ($options as $option) {
// Here I'm trying to get the value given by the user/customer
var_dump($option->getData());
}
}
}
return $this;
}
It is a custom option from a bundle type. So the product can't be configurable.
I'm new to magento so I'm probably missing something.
Can anyone help me?
Hope this piece of code can help you:
public function productFinalPrice($observer){
$product = $observer->getEvent()->getProduct();
$productType=$product->getTypeID();
if($productType == 'your_product_type')
{
$option = $product->getCustomOptions();
$searchedOption = null;
//search for your option;
foreach ($product->getOptions() as $o) {
if($o->getTitle()=="your_attribute_title" && $o->getType()=="your_type_of_option(eg. area"){
$optionId = $o->getOptionId();//got your searched optionId
break;
}
}
foreach($option as $key => $o) {
if($key == "option_".$optionId) {
$searchedOption = $o;
//here you get the option object with the values in it
}
}
$articleNumber = $searchedOption->getData('value'); // getthe value of your option
//calculate final price like you need it
$product->setFinalPrice($finalPrice);
}
return $this;
}
best regards

Codeigniter Cart - Check if item added to cart

I'm using the Cart class in Codeigniter. What I want to do should (hopefully!) be simple... but i'm struggling.
On the product page, I have a button to 'add to cart'. What I want to happen is that when the item is already in the cart, the button changes to 'remove from cart'.
<? //if(**not in cart**) { ?>
Add to cart
<? } else { ?>
Remove from cart
<? } ?>
How can I query the cart to see if that item is in there or not and get the 'rowid' so I can use that for a remove function?
Many thanks!
I had a similar problem - I got round it by extending the CI_Cart library with 2 new functions - in_cart() and all_item_count().
<?php
class MY_Cart extends CI_Cart {
function __construct()
{
parent::__construct();
$this->product_name_rules = '\d\D';
}
/*
* Returns data for products in cart
*
* #param integer $product_id used to fetch only the quantity of a specific product
* #return array|integer $in_cart an array in the form (id => quantity, ....) OR quantity if $product_id is set
*/
public function in_cart($product_id = null) {
if ($this->total_items() > 0)
{
$in_cart = array();
// Fetch data for all products in cart
foreach ($this->contents() AS $item)
{
$in_cart[$item['id']] = $item['qty'];
}
if ($product_id)
{
if (array_key_exists($product_id, $in_cart))
{
return $in_cart[$product_id];
}
return null;
}
else
{
return $in_cart;
}
}
return null;
}
public function all_item_count()
{
$total = 0;
if ($this->total_items() > 0)
{
foreach ($this->contents() AS $item)
{
$total = $item['qty'] + $total;
}
}
return $total;
}
}
/* End of file: MY_Cart.php */
/* Location: ./application/libraries/MY_Cart.php */
You could check in your model if the job name or whatever you would like to check already exists. If it exists display delete button else show add.

Resources