How to implement 15% off on first order in Magento - magento-1.9

I am trying to implement the 15% off your first order. And user can be guest or registered.
Please share any helpful URL or guidance or extension for Magento CE 1.9

Please follow the below code:
<?php
if(Mage::getSingleton('customer/session')->isLoggedIn()){
$customerData = Mage::getSingleton('customer/session')->getCustomer();
$customer_id = $customerData->getId();
$_orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id',$customer_id);
$_orderCnt = $_orders->count(); //orders count
if ($_orderCnt<1){
// Display your discount coupon code for apply in cart page
// Or play with your discount code
}
}
Hope It's work for you.

Related

How to add pagination for wishlist products in magento 1.9

I am trying to get products on the page-wise for wishlist collection. I was getting a count for product collections in the below code. I have set the page size to one but it's showing the product count two. Please help me to fix this. Thanks.
$wishlist1 = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer, true)
->setCurPage($page_num)
->setPageSize(1)
->load();
foreach($wishlist1->getItemCollection() as $product){
$_product = Mage::getModel('catalog/product')->load($product['product_id']);//product id here
echo $product['product_id'];
}
Please try with this code:
<?php
$customer = Mage::getModel("customer/customer")->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail('mohit#streammarket.co.uk');
$wishlistItems = Mage::getModel('wishlist/item')->getCollection()
->setWebsiteId($customer->getWebsiteId())
->setCustomerGroupId($customer->getGroupId())
->setCurPage(1)
->setPageSize(1)
->load();
?>

show subcategories of parent category when no subcategories in category page

In magento when we click on a category it takes us to category page and shows
(if exists) subcategories of the clicked category in layered navigation on left.But when we click on a category that has no subcategories it show empty on that category page in layered navigation on left. What I want is to show subcategories of the parent if the current category has no subcategories.For this I have done the following but did not work for me.
I have tried to add the following to to
app/code/core/Mage/Catalog/Model/Layer/Filter/Category.php
if(count($categoty->getChildrenCategories())){
$categories = $categoty->getChildrenCategories();
}else{
$categories = $categoty->getParentCategory()->getChildrenCategories();
}
and removed line #163
$categories = $categoty->getChildrenCategories();
Please suggest me a solution. Any help will be greatly appreciated.
I have found the solution. I have to put the above login in left.phtml
app/design/frontend/theme/template/catalog/navigation/left.phtml
$categoty = Mage::registry('current_category');
$categories = $category->getChildrenCategories();
//$_categories = $this->getCurrentChildCategories();
if(count($categoty->getChildrenCategories())){
$_categories = $categoty->getChildrenCategories();
}else{
$_categories = $categoty->getParentCategory()->getChildrenCategories();
}
and it worked like a charm! Hope it will help someone else!

BigCommerce Stencil - Product Variant Stock Levels

A client wants to set up A/B testing on the Product Detail Page related to the stock_level of a product's variants. Once the user selects their options, if the quantity is less than 5, I'd show something like "Hurry, only 3 more in stock"...
I believe I have the correct Inventory settings enabled, because I can retrieve the stock_level of a product without options.
Has anyone had success pulling variant SKU stock_levels in stencil?
Thanks
This can be done using javascript in the assets/js/theme/common/product-details.js file. On initial page load and each time a product option is changed, there is a function updateView(data) that is called. The data parameter contains all the info you need for the selected variation.
Starting on line 285, replace this:
updateView(data) {
const viewModel = this.getViewModel(this.$scope);
this.showMessageBox(data.stock_message || data.purchasing_message);
with this:
updateView(data) {
const viewModel = this.getViewModel(this.$scope);
if(data.stock < "5") {
data.stock_message = "Hurry, only " + data.stock + " left!";
}
this.showMessageBox(data.stock_message || data.purchasing_message);

Umbraco MediaById not working as expected

Trying to display a set of images from uComponents' MNTP, and can't get a value for the umbracoFile property - in the example below, both umbracoFile and url return empty strings:
foreach (var id in #Model.sliders) {
var media = Model.MediaById(id.InnerText);
if (media != null){
var url = media.umbracoFile;
<p>name = #media.Name</p>
<p>alt = #media.altText</p>
<p>url = #media.umbracoFile</p>
<p>url = #url</p>
}
}
It's getting really really really annoying... I've worked around it in other areas like so, using Model.Media:
<img src="#Model.Media("topRightImage", "umbracoFile")" alt="#Model.Media("topightImage", "altText")" />
But that will only help if with the media picker data type, not mntp. It shouldnt' be that difficult, should it?
I can get the images to load if I rebuild the internal search index, but they're gone again on subsequent refreshes.
I've seen others having similar problems, and would really appreciate a solution...
ta
Nathan
This looks like a bug that was fixed in 4.7.2. See the following codeplex item:
http://umbraco.codeplex.com/workitem/30778

Magento: Get simple product color from custom table

I'm really struggling with this in Magento 1.10 Enterprise. I have a array of simple products color ids and I want to use this id to query the atb_color table. Raw query:
SELECT description FROM atb_colors WHERE option_id = 'my_color_id'
Here is a method I was trying to build:
public function getColorData($product){
$ids = $product->getTypeInstance()->getUsedProductIds();
foreach($ids as $id){
$simpleproduct = Mage::getModel('catalog/product')->load($id);
-->Query using my_color_id
}
}
I can use this to get name and quantity. If I put this in the foreach loop:
echo $simpleproduct->getName()." - ".(int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($simpleproduct)->getQty() . '<br />';
How would I run this query. Forgive me I am very new to Magento. It's somewhat difficult to grasp some of it. But I'm on a deadline to finish this one section of displaying color and size. Any help? Please, please!!
Thanks in advance
This is the weirdest hack, but if you are really in big hurry
public function getProductCustomColor($product)
{
$ids = $product->getTypeInstance()->getUsedProductIds();
foreach($ids as $id){
$simpleProduct = Mage::getModel('catalog/product')->load($id);
$select = $product->getResource()->getReadConnection()->select()
->from('atb_colors', array('description'))
->where('option_id = :my_color_id');
$colorDescription = $product->getResource()->getReadConnection()
->fetchOne($select, array('option_id' => $simpleProduct->getYourColorId()));
// ...
}
}
To everyone: never write code for magento in this way.