I am trying to remove just one qty from my cart rather than all, but to no avail.
Can anybody help?
Here is the code I have got so far...
require_once 'app/Mage.php';
Mage::app("default");
Mage::getSingleton("core/session", array("name" => "frontend"));
$session = Mage::getSingleton("customer/session");
$yourProId = $_POST['prodID'];
$qty = 1;
foreach (Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item) {
if ($yourProId == $item->getProductId()) {
Mage::getSingleton('checkout/cart')->removeItem($item->getId())->save();
}
}
UPDATE: Here is the code that works, thanks to R.S. for this!
$yourProId = $_POST['prodID'];
$qty=1;
$cartHelper = Mage::helper('checkout/cart');
$items = $cartHelper->getCart()->getItems();
foreach ($items as $item) {
if ($item->getProduct()->getId() == $yourProId) {
$qty = $item->getQty() - 1; // check if greater then 0 or set it to what you want
if($qty == 0) {
Mage::getSingleton('checkout/cart')->removeItem($item->getId());
} else {
$item->setQty($qty);
}
$cartHelper->getCart()->save();
break;
}
}
Try
$cartHelper = Mage::helper('checkout/cart');
$items = $cartHelper->getCart()->getItems();
foreach ($items as $item) {
if ($item->getProduct()->getId() == $yourProId) {
if( $item->getQty() == 1 ){
$cartHelper->getCart()->removeItem($item->getItemId())->save();
}
else if($item->getQty() > 1){
$item->setQty($item->getQty() - 1)
$cartHelper->getCart()->save();
}
break;
}
}
Take a look # /app/code/core/Mage/Checkout/controllers/CartController.php
See http://www.magentocommerce.com/boards/viewthread/30113/
You can alter or remove qty using $quoteItem->setData('qty', $avl_qty);
Please refer to code for more help.
$quoteItem = $observer->getEvent()->getQuoteItem();
$avl_qty = 1;
if ($avl_qty == '0') {
$quoteItem->getQuote()->removeItem($quoteItem->getItemId());
throw new LocalizedException(__("This product is currently out of stock."));
}
elseif ($order_qty > $avl_qty) {
$quoteItem->setData('qty', $avl_qty);
$this->_cart->save();
$this->messageManager->addNoticeMessage('Sorry we have only '.$avl_qty.' qty of this product available');
}
else {
}
For Magento 2
you can utilize
https://yourdomain.com/rest/V1/carts/mine/items
API with Auth token and Body
{
"cartItem": {
"item_id": 49388,//item_id not SKU
"qty": 1, //This will overwrite quantity
"quote_id": {{QuoteId}}
}
}
Related
can anyone help to me.
I have a module for show banners (and stickers) on product. Banner function show a banner only on product page of specific product, and stickers on page of specific product, and product list miniature.
(you can see screenshot) original page is: http://miofantasy.it/shampoo/2192-antica-erboristeria-shampoo-girasole-250-ml.html
screenshot
I want show the BANNER on product list miniature, beyond that product page, like in next screeshot modified (how already stichers does)
screenshot modified
original page is: http://miofantasy.it/
I'm don't know about code edit, and i don't know how to do it.
Anyone can said to me what i must modify.
Inside a file php of module, I have found this code, that i think manage the banner on product page:
public function hookDisplayProductButtons()
{
//Its an alternative, use only if productfooter hook is not available.
// get rid of 1 > 2 condition to activate
if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=') && 1 > 2) {
return $this-> hookDisplayFooterProduct();
}
}
public function hookDisplayFooterProduct()
{
$type = (int)Configuration::get('sticker_type_val');
$type = empty($type) ? 1 : $type;
if ($type > 0) {
$object = new Stickers();
$rules = new Rules();
$id = Tools::getValue('id_product');
$product = new Product((int)$id, true, $this->context->language->id);
$category_data = $product->getCategories();
$stickers_pro = $object->getProductStickers($id);
**$stickers_banner = $object->getProductBanner($id);**
$_price = Tools::ps_round($product->price);
//For Stickers Rules if any matches - Tags
$tags_exist = Tag::getProductTags((int)$id);
$new_stickers_colllection = $rules->keyNewExists();
$is_discounted = (int)$product->isDiscounted($product->id);
if (!empty($tags_exist)) {
$stickers_colllection = $rules->keyTagExists($tags_exist);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Check for reference match
if (!empty($product->reference)) {
$stickers_colllection = $rules->keyRefExists($product->reference);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Check for Price match
if ($_price > 0) {
$stickers_colllection = $rules->keyPriceExists($_price);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
$_stickers_colllection = $rules->keyPriceGreaterExists($_price);
if (!empty($_stickers_colllection)) {
foreach ($_stickers_colllection as $_stick) {
array_push($stickers_pro, $object->getSticker($_stick));
}
}
}
//Check for new Products match
if (!empty($new_stickers_colllection) && (int)$product->new > 0) {
foreach ($new_stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Check for Dsicounted Product rules
if ($is_discounted > 0) {
$stickers_colllection = $rules->keySaleExists();
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Finally check for category rule existance
$rule_category = $rules->getAllApplicable('category');
if (count($rule_category) > 0)
{
$category_applicable = array();
foreach ($category_data as $key)
{
$return = $rules->getIsCategoryStickerApplicable($key);
if (!empty($return))
{
$return = array_shift($return);
array_push($category_applicable, $return);
}
}
if (count($category_applicable) > 0)
{
foreach ($category_applicable as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Now check for brands rule existance
$rule_brands = $rules->getAllApplicable('brand');
if (count($rule_brands) > 0)
{
$stickers_colllection = $rules->keyBrandsExists($rule_brands, (int)$product->id_manufacturer);
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Now check for supplier rule existance
$rule_supplier = $rules->getAllApplicable('supplier');
if (count($rule_supplier) > 0 && (int)$product->id_supplier > 0)
{
$stickers_colllection = $rules->keySupplierExists($rule_supplier, (int)$product->id_supplier);
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
//echo '<pre>'; print_r($stickers_colllection); exit;
}
$base_image = __PS_BASE_URI__.'img/';
$position = Configuration::get('sticker_pos');
$size = Configuration::get('sticker_size');
$this->context->smarty->assign('base_image', $base_image);
$this->context->smarty->assign('size', $size);
$this->context->smarty->assign('position', $position);
$this->context->smarty->assign('id', $id);
$this->context->smarty->assign('stickers', $stickers_pro);
$this->context->smarty->assign('module_dir', _PS_MODULE_DIR_);
**$this->context->smarty->assign('stickers_banner', $stickers_banner);**
$force_ssl = (Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'));
$this->context->smarty->assign(array(
'base_dir' => _PS_BASE_URL_.__PS_BASE_URI__,
'base_dir_ssl' => _PS_BASE_URL_SSL_.__PS_BASE_URI__,
'force_ssl' => $force_ssl
)
);
if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=') == true) {
return $this->display(__FILE__, 'views/templates/hook/productfooter_17.tpl');
} else {
return $this->display(__FILE__, 'views/templates/hook/productfooter.tpl');
}
}
}
In bold character stickers_banner that i think manage the banner.
'views/templates/hook/productfooter_17.tpl' is the file where I find the file that i think manage banner layout, like this:
{if !empty($stickers_banner.title)}
{if empty($stickers)}<script type="text/javascript" src="{if $force_ssl ==
1}{$base_dir_ssl|escape:'htmlall':'UTF-8'}{else}
{$base_dir|escape:'htmlall':'UTF-8'}{/if}js/jquery/jquery-1.11.0.min.js">
</script>{/if}
{literal}
<script>
$('.product-price').after({/literal}'<div style="padding:10px 6px; margin-
bottom:10px; text-align:center;background:
{$stickers_banner.bg_color|escape:'htmlall':'UTF-8'};color:
{$stickers_banner.color|escape:'htmlall':'UTF-8'};border:1px solid
{$stickers_banner.border_color|escape:'htmlall':'UTF-8'};font-family:
{$stickers_banner.font|escape:'htmlall':'UTF-8'};font-size:
{$stickers_banner.font_size|escape:'htmlall':'UTF-8'}px;font-weight:
{$stickers_banner.font_weight|escape:'htmlall':'UTF-8'};">
{$stickers_banner.title|escape:'htmlall':'UTF-8'}</div>'{literal});
</script>
{/literal}
{/if}
Now the hook that i think to must modify for show banner in product list;
public function hookdisplayProductListFunctionalButtons($params)
{
$id = (int)$params['product']['id_product'];
$id = ($id <= 0) ? Tools::getValue('id_product') : $id;
$product = new Product((int)$id, true, $this->context->language->id);
$category_data = $product->getCategories();
$type = Configuration::get('sticker_type_val');
$type = empty($type) ? 1 : $type;
$stickers_pro = array();
$object = new Stickers();
$rules = new Rules();
$_price = Tools::ps_round($product->price);
//$page_name = Dispatcher::getInstance()->getController();
if ($type == 1) {
$new_stickers_colllection = $rules->keyNewExists();
$is_discounted = (int)$product->isDiscounted($product->id);
//For Stickers Rules if any matches
$tags_exist = Tag::getProductTags((int)$id);
if (!empty($tags_exist)) {
$stickers_colllection = $rules->keyTagExists($tags_exist);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Check for reference match
if (!empty($product->reference)) {
$stickers_colllection = $rules->keyRefExists($product->reference);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Check for Price match
if ($_price > 0) {
$stickers_colllection = $rules->keyPriceExists($_price);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
$_stickers_colllection = $rules->keyPriceGreaterExists($_price);
if (!empty($_stickers_colllection)) {
foreach ($_stickers_colllection as $_stick) {
array_push($stickers_pro, $object->getSticker($_stick));
}
}
}
//Check for new Products match
if (!empty($new_stickers_colllection) && (int)$product->new > 0) {
foreach ($new_stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Check for Discounted Product rules
if ($is_discounted > 0) {
$stickers_colllection = $rules->keySaleExists();
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Finally check for category rule existance
$rule_category = $rules->getAllApplicable('category');
if (count($rule_category) > 0)
{
$category_applicable = array();
foreach ($category_data as $key)
{
$return = $rules->getIsCategoryStickerApplicable($key);
if (!empty($return))
{
$return = array_shift($return);
array_push($category_applicable, $return);
}
}
if (count($category_applicable) > 0)
{
foreach ($category_applicable as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Now check for brands rule existance
$rule_brands = $rules->getAllApplicable('brand');
if (count($rule_brands) > 0)
{
$stickers_colllection = $rules->keyBrandsExists($rule_brands, (int)$product->id_manufacturer);
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Now check for supplier rule existance
$rule_supplier = $rules->getAllApplicable('supplier');
if (count($rule_supplier) > 0 && (int)$product->id_supplier > 0)
{
$stickers_colllection = $rules->keySupplierExists($rule_supplier, (int)$product->id_supplier);
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
//echo '<pre>'; print_r($stickers_colllection); exit;
}
}
$position = Configuration::get('sticker_pos');
$size = Configuration::get('sticker_size');
$base_image = __PS_BASE_URI__.'img/';
$this->context->smarty->assign('base_image', $base_image);
$this->context->smarty->assign('name', $params['product']['name']);
$this->context->smarty->assign('size', $size);
$this->context->smarty->assign('position', $position);
$this->context->smarty->assign('module_dir', _PS_MODULE_DIR_);
$this->context->smarty->assign('id', $id);
if ($type == 1) {
$stickercollection_ = $object->getProductStickers($params['product']['id_product']);
foreach ($stickercollection_ as $stick) {
array_push($stickers_pro, $stick);
}
}
$this->context->smarty->assign('stickers', $stickers_pro);
$force_ssl = (Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'));
$this->context->smarty->assign(array(
'base_dir' => _PS_BASE_URL_.__PS_BASE_URI__,
'base_dir_ssl' => _PS_BASE_URL_SSL_.__PS_BASE_URI__,
'force_ssl' => $force_ssl
)
);
if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=') == true) {
return $this->display(__FILE__, 'views/templates/hook/listing_17.tpl');
} else {
return $this->display(__FILE__, 'views/templates/hook/listing.tpl');
}
}
There is also hookdisplayStickers, i don't know if is impotant for this.
What can I modify for show the banner in product list.
Please anyone can help me?
Thanks
UPDATE:
I have add code
public function hookDisplayProductPriceBlock($params)
{
if ($params['type'] == 'before_price') {
// old_price or unit_price or weight
$id = (int)$params['product']['id_product'];
$_POST('id_product') = $id;
return $this->hookDisplayFooterProduct();
}
}
below hookdisplayProductListFunctionalButtons, and I have added code for register hook displayProductPriceBlock
public function install()
{
if (!$this->existsTab($this->tab_class)) {
if (!$this->addTab($this->tab_class, 0)) {
return false;
}
}
mkdir(_PS_IMG_DIR_.'stickers', 0777, true);
if (!parent::install()
|| !$this->installDb()
|| !$this->registerHook('displayCatalogListing')
|| !$this->registerHook('displayProductListFunctionalButtons')
|| !$this->registerHook('displayProductPriceBlock')
|| !$this->registerHook('displayAdminProductsExtra')
|| !$this->registerHook('actionProductUpdate')
|| !$this->registerHook('displayBackOfficeHeader')
|| !$this->registerHook('displayProductListReviews')
|| !$this->registerHook('displayProductButtons')
|| !$this->registerHook('displayFooterProduct')) {
return false;
}
return true;
}
But when I install module, I have error and prestashop not install module. I have used hookDisplayPriceBlock because I have found already writed hookDisplayProductListReviews :
public function hookDisplayProductListReviews($params)
{
if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=')) {
return $this->hookdisplayProductListFunctionalButtons($params);
}
}
that i think it redirect prestashop 1.7 to hookdisplayProductListFunctionalButtons.
I was thinking, if hookDisplayProductListReviews redirect to hookdisplayProductListFunctionalButtons, is possible to edit hookdisplayProductListFunctionalButtons and add the code for show the banner, like in hookDisplayFooterProduct, where is written specific code for show the Banner?
How to do?
Thanks
You have to modify your banner module to do it.
Probably the problem will be solved by adding new hook (displayProductListFunctionalButtons or displayProductPriceBlock) to this module.
It requires the ability to cretae the module for Prestashop.
UPDATE :
Prestashop seems to have removed HookdisplayProductListFunctionalButtons from version 1.7
So you can use displayProductPriceBlock or displayProductListReviews :
public function HookDisplayProductListReviews($params)
{
$id = (int)$params['product']['id_product'];
$_POST('id_product') = $id;
return $this->hookDisplayFooterProduct();
}
If you want to use displayProductPriceBlock, you have to pay attention that it has several positions:
public function displayProductPriceBlock($params)
{
if($params['type'] == 'before_price') { // old_price or unit_price or weight
$id = (int)$params['product']['id_product'];
$_POST('id_product') = $id;
return $this->hookDisplayFooterProduct();
}
}
Tip: Do not forget that new hooks should be registered in the module installation method:
$this->registerHook('HookDisplayProductListReviews');
Is there any way that we can remove the Items from the cart. Actually I have dynamic Grouped products were I need to allow the user to buy the item inside the grouped product. Now when someone only select the Item under the grouped product then it allow to buy that and need to stop or remove the group product from the cart.
I had tried with checkout_cart_product_add_after Observer and used below logic, but it is not working
$cartHelper = Mage::helper('checkout/cart');
$items = $cartHelper->getCart()->getItems();
foreach ($items as $item) {
if ($item->getProduct()->getId() == $productId) {
$itemId = $item->getItemId();
$cartHelper->getCart()->removeItem($itemId)->save();
break;
}
}
return;
Please help me guys.
Thanks in advance.
Standalone example:
$oCheckout = Mage::getSingleton( 'checkout/session' );
$oQuote = $oCheckout->getQuote();
var_dump( $oQuote );
$oCart = $oQuote->getAllItems();
if( !empty( $oCart ) )
{
foreach ( $oCart as $oItem )
{
// Specify conditionals
if( $oItem->getProduct()->getSku() == 1 )
{
// Note to use Shopping cart id not product id.
$oQuote->removeItem( $oItem->getId() )
->save();
}
}
}
var_dump( $oQuote );
Try this in your observer:
$product = $observer->getEvent()->getProduct();
$cart = Mage::getSingleton('checkout/cart');
foreach ($cart->getQuote()->getItemsCollection() as $_item) {
if ($_item->getProductId() == $product->getId()) {
$_item->isDeleted(true);
}
}
}
I have page of articles with more than 5 results. 5 results are displayed per page. Pagination shows up. When I go to different pages however, every page has the same 5 results.
My getItems():
function getItems()
{
$params = $this->getState()->get('params');
$limit = $this->getState('list.limit');
// 5
if ($this->_articles === null && $category = $this->getCategory()) {
$model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
$model->setState('params', JFactory::getApplication()->getParams());
$model->setState('filter.category_id', $category->id);
$model->setState('filter.published', $this->getState('filter.published'));
$model->setState('filter.access', $this->getState('filter.access'));
$model->setState('filter.language', $this->getState('filter.language'));
$model->setState('list.ordering', $this->_buildContentOrderBy());
$model->setState('list.start', $this->getState('list.start'));
$model->setState('list.limit', $limit);
$model->setState('list.direction', $this->getState('list.direction'));
$model->setState('list.filter', $this->getState('list.filter'));
// filter.subcategories indicates whether to include articles from subcategories in the list or blog
$model->setState('filter.subcategories', $this->getState('filter.subcategories'));
$model->setState('filter.max_category_levels', $this->setState('filter.max_category_levels'));
$model->setState('list.links', $this->getState('list.links'));
if ($limit >= 0) {
$this->_articles = $model->getItems();
if ($this->_articles === false) {
$this->setError($model->getError());
}
}
else {
$this->_articles=array();
}
$this->_pagination = $model->getPagination();
}
$filterResult = null;
return $this->_articles;
}
My populate state:
protected function populateState($ordering = null, $direction = null)
{
// Initiliase variables.
$app = JFactory::getApplication('site');
$pk = JRequest::getInt('id');
$this->setState('category.id', $pk);
// Load the parameters. Merge Global and Menu Item params into new object
$params = $app->getParams();
$menuParams = new JRegistry;
if ($menu = $app->getMenu()->getActive()) {
$menuParams->loadString($menu->params);
}
$mergedParams = clone $menuParams;
$mergedParams->merge($params);
$this->setState('params', $mergedParams);
$user = JFactory::getUser();
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
$groups = implode(',', $user->getAuthorisedViewLevels());
if ((!$user->authorise('core.edit.state', 'com_content')) && (!$user->authorise('core.edit', 'com_content'))){
// limit to published for people who can't edit or edit.state.
$this->setState('filter.published', 1);
/**
* Custom Author Filter
*/
if (JRequest::getVar('author')) {
$this->setState('filter.created_by', $this->getUserId(JRequest::getVar('author')));
}
// Filter by start and end dates.
$nullDate = $db->Quote($db->getNullDate());
$nowDate = $db->Quote(JFactory::getDate()->toMySQL());
$query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')');
$query->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')');
/**
* Custom Author Filter
*/
if (JRequest::getVar('author')) {
$query->where('(a.created_by = "' . $this->getUserId(JRequest::getVar('author')) . '")');
}
}
// process show_noauth parameter
if (!$params->get('show_noauth')) {
$this->setState('filter.access', true);
}
else {
$this->setState('filter.access', false);
}
// Optional filter text
$this->setState('list.filter', JRequest::getString('filter-search'));
// filter.order
$itemid = JRequest::getInt('id', 0) . ':' . JRequest::getInt('Itemid', 0);
$orderCol = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.filter_order', 'filter_order', '', 'string');
if (!in_array($orderCol, $this->filter_fields)) {
$orderCol = 'a.ordering';
}
$this->setState('list.ordering', $orderCol);
$listOrder = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.filter_order_Dir',
'filter_order_Dir', '', 'cmd');
if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', ''))) {
$listOrder = 'ASC';
}
$this->setState('list.direction', $listOrder);
//$this->setState('list.start', JRequest::getVar('limitstart', 0, '', 'int'));
// set limit for query. If list, use parameter. If blog, add blog parameters for limit.
if ((JRequest::getCmd('layout') == 'blog') || $params->get('layout_type') == 'blog') {
$limit = $params->get('num_leading_articles') + $params->get('num_intro_articles') + $params->get('num_links');
$this->setState('list.links', $params->get('num_links'));
}
else {
$limit = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.limit', 'limit', $params->get('display_num'));
}
$this->setState('list.limit', $limit);
// set the depth of the category query based on parameter
$showSubcategories = $params->get('show_subcategory_content', '0');
if ($showSubcategories) {
$this->setState('filter.max_category_levels', $params->get('show_subcategory_content', '1'));
$this->setState('filter.subcategories', true);
}
$this->setState('filter.language',$app->getLanguageFilter());
$this->setState('layout', JRequest::getCmd('layout'));
}
My display function de view.html.php
function display($tpl = null)
{
$app = JFactory::getApplication();
$user = JFactory::getUser();
// Get some data from the models
$state = $this->get('State');
$params = $state->params;
$items = $this->get('Items');
$contactId = JRequest::getVar('author');
if($contactId){
$this->setUserId($contactId);
$this->setContactName($this->userId);
}
$category = $this->get('Category');
$children = $this->get('Children');
$parent = $this->get('Parent');
$pagination = $this->get('Pagination');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
if ($category == false) {
return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
}
if ($parent == false) {
return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
}
// Setup the category parameters.
$cparams = $category->getParams();
$category->params = clone($params);
$category->params->merge($cparams);
// Check whether category access level allows access.
$user = JFactory::getUser();
$groups = $user->getAuthorisedViewLevels();
if (!in_array($category->access, $groups)) {
return JError::raiseError(403, JText::_("JERROR_ALERTNOAUTHOR"));
}
// PREPARE THE DATA
// Get the metrics for the structural page layout.
$numLeading = $params->def('num_leading_articles', 1);
$numIntro = $params->def('num_intro_articles', 4);
$numLinks = $params->def('num_links', 4);
// Compute the article slugs and prepare introtext (runs content plugins).
for ($i = 0, $n = count($items); $i < $n; $i++)
{
$item = &$items[$i];
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
// No link for ROOT category
if ($item->parent_alias == 'root') {
$item->parent_slug = null;
}
$item->event = new stdClass();
$dispatcher = JDispatcher::getInstance();
// Ignore content plugins on links.
if ($i < $numLeading + $numIntro) {
$item->introtext = JHtml::_('content.prepare', $item->introtext);
$results = $dispatcher->trigger('onContentAfterTitle', array('com_content.article', &$item, &$item->params, 0));
$item->event->afterDisplayTitle = trim(implode("\n", $results));
$results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.article', &$item, &$item->params, 0));
$item->event->beforeDisplayContent = trim(implode("\n", $results));
$results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.article', &$item, &$item->params, 0));
$item->event->afterDisplayContent = trim(implode("\n", $results));
}
}
// Check for layout override only if this is not the active menu item
// If it is the active menu item, then the view and category id will match
$active = $app->getMenu()->getActive();
if ((!$active) || ((strpos($active->link, 'view=category') === false) || (strpos($active->link, '&id=' . (string) $category->id) === false))) {
// Get the layout from the merged category params
if ($layout = $category->params->get('category_layout')) {
$this->setLayout($layout);
}
}
// At this point, we are in a menu item, so we don't override the layout
elseif (isset($active->query['layout'])) {
// We need to set the layout from the query in case this is an alternative menu item (with an alternative layout)
$this->setLayout($active->query['layout']);
}
// For blog layouts, preprocess the breakdown of leading, intro and linked articles.
// This makes it much easier for the designer to just interrogate the arrays.
if (($params->get('layout_type') == 'blog') || ($this->getLayout() == 'blog')) {
$max = count($items);
// The first group is the leading articles.
$limit = $numLeading;
for ($i = 0; $i < $limit && $i < $max; $i++) {
$this->lead_items[$i] = &$items[$i];
}
// The second group is the intro articles.
$limit = $numLeading + $numIntro;
// Order articles across, then down (or single column mode)
for ($i = $numLeading; $i < $limit && $i < $max; $i++) {
$this->intro_items[$i] = &$items[$i];
}
$this->columns = max(1, $params->def('num_columns', 1));
$order = $params->def('multi_column_order', 1);
if ($order == 0 && $this->columns > 1) {
// call order down helper
$this->intro_items = ContentHelperQuery::orderDownColumns($this->intro_items, $this->columns);
}
$limit = $numLeading + $numIntro + $numLinks;
// The remainder are the links.
for ($i = $numLeading + $numIntro; $i < $limit && $i < $max;$i++)
{
$this->link_items[$i] = &$items[$i];
}
}
$children = array($category->id => $children);
//Escape strings for HTML output
$this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
$this->assign('maxLevel', $params->get('maxLevel', -1));
$this->assignRef('state', $state);
$this->assignRef('items', $items);
$this->assignRef('category', $category);
$this->assignRef('children', $children);
$this->assignRef('params', $params);
$this->assignRef('parent', $parent);
$this->assignRef('pagination', $pagination);
$this->assignRef('user', $user);
$this->_prepareDocument();
parent::display($tpl);
}
If i print the contents of $pagination in the view.html.php here:
$this->_prepareDocument();
echo '<pre>'; print_r($pagination); exit();
parent::display($tpl);
I get the following results:
In my template file I echo the pagination:
<?php echo $this->pagination->getPagesLinks(); ?>
By the way, clicking on 'next' does change the url into ...?start=5.
This line in populateState is commented out
$this->setState('list.start', JRequest::getVar('limitstart', 0, '', 'int'));
Uncomment it change it tot get the "start" parameter:
$this->setState('list.start', JRequest::getVar('start', 0, '', 'int'));
I want to create partial invoice for downloadable product of an order based on release date of that product, I have got so many solutions to create partial invoice but it's create the invoice for all product, not for selected one.
Here is the solution but don't forget to change condition according your requirement.
<?php
require_once '../app/Mage.php';
Mage::app('admin');
CapturePayment::createInvoice();
class CapturePayment {
public static function createInvoice() {
$orders = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('status', array('processing'));
foreach ($orders as $order) {
$orderId = $order->getIncrementId();
try {
if (!$order->getId() || !$order->canInvoice()) {
echo 'Invoice is not allowed for order=>.' . $orderId . "\n";
continue;
}
$items = $order->getAllItems();
$partial = false;
$qtys = array();
foreach ($items as $item) {
/* Check wheter we can create invoice for this item or not */
if (!CapturePayment::canInvoiceItem($item, array())) {
continue;
}
/* Get product id on the basis of order item id */
$productId = $item->getProductId();
/* If product is tablet then don't create invoice for the same */
/* Put your condition here for items you want to create the invoice e.g.*/
/* Load the product to get the release date */
$productDetails = Mage::getModel('catalog/product')->load($productId);
/* create your $qtys array here like */
$qtys['orderItemId'] = 'quantityOrdered';
/* NOTE: But if you don't want to craete invoice for any particular item then pass the '0' quantity for that item and set the value for $partial = true if some product remain in any order*/
}
/* Prepare the invoice to capture/create the invoice */
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice($qtys);
if (!$invoice->getTotalQty()) {
continue;
}
$amount = $invoice->getGrandTotal();
if ($partial) {
$amount = $invoice->getGrandTotal();
$invoice->register()->pay();
$invoice->getOrder()->setIsInProcess(true);
$history = $invoice->getOrder()->addStatusHistoryComment('Partial amount of $' . $amount . ' captured automatically.', false);
$history->setIsCustomerNotified(true);
$invoice->sendEmail(true, '');
$order->save();
Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder())
->save();
$invoice->save();
} else {
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();
$invoice->getOrder()->setCustomerNoteNotify(true);
$invoice->getOrder()->setIsInProcess(false);
$invoice->getOrder()->setData('state', "complete");
$invoice->getOrder()->setStatus("complete");
$invoice->sendEmail(true, '');
$order->save();
Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder())
->save();
$invoice->save();
}
} catch (Exception $e) {
echo 'Exception in Order => ' . $orderId . '=>' . $e . "\n";
}
}
}
/* Check the invoice status for an item of an order */
public static function canInvoiceItem($item, $qtys=array()) {
if ($item->getLockedDoInvoice()) {
return false;
}
if ($item->isDummy()) {
if ($item->getHasChildren()) {
foreach ($item->getChildrenItems() as $child) {
if (empty($qtys)) {
if ($child->getQtyToInvoice() > 0) {
return true;
}
} else {
if (isset($qtys[$child->getId()]) && $qtys[$child->getId()] > 0) {
return true;
}
}
}
return false;
} else if ($item->getParentItem()) {
$parent = $item->getParentItem();
if (empty($qtys)) {
return $parent->getQtyToInvoice() > 0;
} else {
return isset($qtys[$parent->getId()]) && $qtys[$parent->getId()] > 0;
}
}
} else {
return $item->getQtyToInvoice() > 0;
}
}
}
I'm overriding the mod_mainmenu module in Joomla 1.5 and am unable to get the .active or #current CSS class or ID to show on the page. It's showing the following HTML for the menu:
<ul id="top-nav" class="flatList">
<li access="0" level="1" id="1">
<a href="#">
<span class="embed embed-top-nav">Home</span>
<p>news, highlights</p>
</a>
</li>
<li access="0" level="1" id="4">
<a href="/content/index.php?option=com_content&view=article&id=1&Itemid=4">
<span class="embed embed-top-nav">Watch UNC-TV</span>
<p>schedule, programs</p>
</a>
</li>
</ul>
I've read that the mod_mainmenu will automatically insert either active or current somewhere into this so you can tell which item is the currently active menu selection. But I'm not seeing either of those in the generated HTML. I'd like to apply some CSS to the active element, but there doesn't seem to be any way to do this. Any thoughts?
Thanks.
UPDATE: Here's the code of the mod_mainmenu I've created:
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
if ( ! defined('fancyMenuPatch') )
{
function fancyMenuPatch($result,$tag){
$menu = JSite::getMenu();
$active = $menu->getActive();
// Add to the start of the UL tag.
$begin_ul = "<ul id=\"top-nav\" class=\"flatList\">";
$begin_span = "<span class=\"embed embed-top-nav\">";
$home_p = "Home</span><p>news, highlights</p></a>";
$watch_p = "Watch UNC-TV</span><p>schedule, programs</p></a>";
$learn_p = "Learn</span><p>education, unc-tv kids</p></a>";
$support_p = "Support Us</span><p>pledge, volunteer, corporate</p></a>";
$contact_p = "Contact</span><p>feedback, connect, share</p></a>";
// do the replacements
$result = str_replace("<ul class=\"menu\">",$begin_ul, $result);
$result = str_replace("<span>", $begin_span, $result);
$result = str_replace("Home</span></a>",$home_p,$result);
$result = str_replace("Watch UNC-TV</span></a>",$watch_p,$result);
$result = str_replace("Learn</span></a>",$learn_p,$result);
$result = str_replace("Support Us</span></a>",$support_p,$result);
$result = str_replace("Contact</span></a>",$contact_p,$result);
return $result;
}
define('fancyMenuPatch', true);
}
if ( ! defined('modMainMenuXMLCallbackDefined') )
{
function modMainMenuXMLCallback(&$node, $args)
{
$user = &JFactory::getUser();
$menu = &JSite::getMenu();
$active = $menu->getActive();
$path = isset($active) ? array_reverse($active->tree) : null;
if (($args['end']) && ($node->attributes('level') >= $args['end']))
{
$children = $node->children();
foreach ($node->children() as $child)
{
if ($child->name() == 'ul') {
$node->removeChild($child);
}
}
}
if ($node->name() == 'ul') {
foreach ($node->children() as $child)
{
if ($child->attributes('access') > $user->get('aid', 0)) {
$node->removeChild($child);
}
}
}
if (($node->name() == 'li') && isset($node->ul)) {
$node->addAttribute('class', 'parent');
}
if (isset($path) && (in_array($node->attributes('id'), $path) || in_array($node->attributes('rel'), $path)))
{
if ($node->attributes('class')) {
$node->addAttribute('class', $node->attributes('class').' active');
} else {
$node->addAttribute('class', 'active');
}
}
else
{
if (isset($args['children']) && !$args['children'])
{
$children = $node->children();
foreach ($node->children() as $child)
{
if ($child->name() == 'ul') {
$node->removeChild($child);
}
}
}
}
if (($node->name() == 'li') && ($id = $node->attributes('id'))) {
if ($node->attributes('class')) {
$node->addAttribute('class', $node->attributes('class').' item'.$id);
} else {
$node->addAttribute('class', 'item'.$id);
}
}
if (isset($path) && $node->attributes('id') == $path[0]) {
$node->addAttribute('id', 'current');
} else {
$node->removeAttribute('id');
}
$node->removeAttribute('rel');
$node->removeAttribute('level');
$node->removeAttribute('access');
}
define('modMainMenuXMLCallbackDefined', true);
}
ob_start();
modMainMenuHelper::render($params, 'modMyMainMenuXMLCallback');
$menu_html = ob_get_contents();
ob_end_clean();
if($params->get('menutype')=="mainmenu"){
$tag = $params->get('tag_id');
}
//output the menu!
echo fancyMenuPatch($menu_html,$tag);
?>
Try this, here's code for mod_mainmenu (override):
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
if ( ! defined('fancyMenuPatch') )
{
function fancyMenuPatch($result,$tag){
$menu = JSite::getMenu();
$active = $menu->getActive();
// Add to the start of the UL tag.
$begin_ul = "<ul id=\"top-nav\" class=\"flatList\">";
$begin_span = "<span class=\"embed embed-top-nav\">";
$home_p = "Home</span><p>news, highlights</p></a>";
$watch_p = "Watch UNC-TV</span><p>schedule, programs</p></a>";
$learn_p = "Learn</span><p>education, unc-tv kids</p></a>";
$support_p = "Support Us</span><p>pledge, volunteer, corporate</p></a>";
$contact_p = "Contact</span><p>feedback, connect, share</p></a>";
// do the replacements
$result = str_replace("<ul class=\"menu\">",$begin_ul, $result);
$result = str_replace("<span>", $begin_span, $result);
$result = str_replace("Home</span></a>",$home_p,$result);
$result = str_replace("Watch UNC-TV</span></a>",$watch_p,$result);
$result = str_replace("Learn</span></a>",$learn_p,$result);
$result = str_replace("Support Us</span></a>",$support_p,$result);
$result = str_replace("Contact</span></a>",$contact_p,$result);
return $result;
}
define('fancyMenuPatch', true);
}
if ( ! defined('modMyMainMenuXMLCallbackDefined') )
{
function modMyMainMenuXMLCallback(&$node, $args)
{
$user = &JFactory::getUser();
$menu = &JSite::getMenu();
$active = $menu->getActive();
$path = isset($active) ? array_reverse($active->tree) : null; if (($args['end']) && ($node->attributes('level') >= $args['end']))
{
$children = $node->children();
foreach ($node->children() as $child)
{
if ($child->name() == 'ul') {
$node->removeChild($child);
}
}
}
if ($node->name() == 'ul') {
foreach ($node->children() as $child)
{
if ($child->attributes('access') > $user->get('aid', 0)) {
$node->removeChild($child);
}
}
}
if (($node->name() == 'li') && isset($node->ul)) {
$node->addAttribute('class', 'parent');
}
if (isset($path) && in_array($node->attributes('id'), $path))
{
if ($node->attributes('class')) {
$node->addAttribute('class', $node->attributes('class').' active');
} else {
$node->addAttribute('class', 'active');
}
}
else
{
if (isset($args['children']) && !$args['children'])
{
$children = $node->children();
foreach ($node->children() as $child)
{
if ($child->name() == 'ul') {
$node->removeChild($child);
}
}
}
}
if (($node->name() == 'li') && ($id = $node->attributes('id'))) {
if ($node->attributes('class')) {
$node->addAttribute('class', $node->attributes('class').' item'.$id);
} else {
$node->addAttribute('class', 'item'.$id);
}
}
if (isset($path) && $node->attributes('id') == $path[0]) {
$node->addAttribute('id', 'current');
} else {
$node->removeAttribute('id');
}
$node->removeAttribute('level');
$node->removeAttribute('access');
}
define('modMyMainMenuXMLCallbackDefined', true);
}
ob_start();
modMainMenuHelper::render($params, 'modMyMainMenuXMLCallback');
$menu_html = ob_get_contents();
ob_end_clean();
if($params->get('menutype')=="mainmenu"){
$tag = $params->get('tag_id');
}
//output the menu!
echo fancyMenuPatch($menu_html,$tag);
?>
Check your template folder, there is a template.css file, you can find there !