wget -q -O - http://www.example.com/test >/dev/null 2>&1
Shopify, Shopify Apps, Magento, WordPress, Codeigniter, Joomla, Big Commerce | PHP
Wednesday, 2 September 2015
Tuesday, 1 September 2015
How to create shipping and invoice in magneto by code or API
Various merchants, various demands. Imagine you have a private on site
sale or something like that, where your checkout requirements are pretty
simply: create invoice / ship and complete the order all at once. For
example, you are doing the checkout for bunch of people standing in
front of you, paying you money right on the spot. In such scenario
overload of manually creating an invoice and shipment can be too much.
Thus, having your Magento automatically invoice/ship/complete orders can be a logical request. So how do we do that?
Easy! All you need to do is to observe the sales_order_save_after event or observe the controller_action_predispatch event and target the Mage_Checkout_OnepageController::successAction() catching the Mage::getSingleton(‘checkout/session’)->getLastOrderId(). In this example I decided to demonstrate the possible (not ideal, or not even the best) “sales_order_save_after event” approach.
And here is the code for our observer model.
$order = $observer->getEvent()->getOrder(); $orders = Mage::getModel('sales/order_invoice')->getCollection() ->addAttributeToFilter('order_id', array('eq'=>$order->getId())); $orders->getSelect()->limit(1); if ((int)$orders->count() !== 0) { return $this; } if ($order->getState() == Mage_Sales_Model_Order::STATE_NEW) { try { if(!$order->canInvoice()) { $order->addStatusHistoryComment('Inchoo_Invoicer: Order cannot be invoiced.', false); $order->save(); } //START Handle Invoice $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice(); $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE); $invoice->register(); $invoice->getOrder()->setCustomerNoteNotify(false); $invoice->getOrder()->setIsInProcess(true); $order->addStatusHistoryComment('Automatically INVOICED by Invoicer.', false); $transactionSave = Mage::getModel('core/resource_transaction') ->addObject($invoice) ->addObject($invoice->getOrder()); $transactionSave->save(); //END Handle Invoice //START Handle Shipment $shipment = $order->prepareShipment(); $shipment->register(); $order->setIsInProcess(true); $order->addStatusHistoryComment('Automatically SHIPPED by Invoicer.', false); $transactionSave = Mage::getModel('core/resource_transaction') ->addObject($shipment) ->addObject($shipment->getOrder()) ->save(); //END Handle Shipment } catch (Exception $e) { $order->addStatusHistoryComment('Inchoo_Invoicer: Exception occurred during automaticallyInvoiceShipCompleteOrder action. Exception message: '.$e->getMessage(), false); $order->save(); } }
Thursday, 27 August 2015
Redirect all urls exactly, just change domain name
How to change domain using htaccess file
Many times we have a in CMS and Ecommerce website to change the domain due to maintenance or other reason but the main headache is the suburl (categories or collection) should be work as it is other wise we need to write the 301 url redirect for each and every url to not get the SEO errors.
This is tutorial will be help for the following CMS :
- wordpress development
- Joomal development
- Drupal development
- Magento development
- Opencart development
- Woocommerce
- Virtumart
RewriteEngine On RewriteCond %{HTTP_HOST} ^(?:www\.)domain\.com$ [NC] RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301]
Saturday, 22 August 2015
Get controller, module, action and router name
You can easily get controller name, action name,
router name and module name in any template file or class file.
IN TEMPLATE FILES$this->getRequest() can be used in template (phtml) files.
/** * get Controller name */ $this->getRequest()->getControllerName(); /** * get Action name, i.e. the function inside the controller */ $this->getRequest()->getActionName(); /** * get Router name */ $this->getRequest()->getRouteName(); /** * get module name */ $this->getRequest()->getModuleName();
/** * get Current URL */
$currentUrl = Mage::helper('core/url')->getCurrentUrl(); $url = Mage::getSingleton('core/url')->parseUrl($currentUrl); $path = $url->getPath();
IN CLASS FILES
/*** get Controller name*/Mage::app()->getRequest()->getControllerName();/*** get Action name, i.e. the function inside the controller*/Mage::app()->getRequest()->getActionName();/*** get Router name*/Mage::app()->getRequest()->getRouteName();/*** get module name*/Mage::app()->getRequest()->getModuleName();
Thursday, 20 August 2015
Simple Ajax add to cart in magento
list.phtml page in template
<form class="product_addtocart_form" action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if(!$_product->isGrouped()): ?>
<label for="qty" class="qtylabel" style=""><?php echo $this->__('Qty') ?>:</label>
<input type="text" class="form-control qtybox" name="qty">
<?php endif; ?>
<button type="submit" class="link_cart"><span><i class="fa fa-shopping-cart" style="margin-right: 5px;"></i><?php echo $this->__('Add to Cart') ?></span></button>
</form>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('.product_addtocart_form').submit(function(event){
event.preventDefault();
var $this = jQuery(this);
jQuery($this).parents('li').append('<div class="ajax_loader"></div>');
url = jQuery(this).attr('action');
console.log(jQuery(this).serialize());
url += '&isAjax=1';
var data = jQuery(this).serialize();
data += '&isAjax=1';
jQuery.ajax({
url : url,
dataType : 'json',
type : 'post',
data : data,
success : function(data) {
getcartdata($this);
}
});
setTimeout(function(){
//getcartdata($this);
},1000);
});
});
function getcartdata($this){
jQuery.ajax( {
url : "<?php echo Mage::getBaseUrl().'getcitys/index/getcartdetail'; ?>",
dataType : 'html',
type : 'get',
success : function(data) {
jQuery('.ajax_loader').hide();
jQuery('.block-cart-header').html(data);
}
});
}
</script>
Make in controllers/IndexController.php
public function getcartdetailAction() {
$block = $this->getLayout()->createBlock('checkout/cart_sidebar');
$block->setTemplate('checkout/cart/sidebar_header_ajax.phtml');
echo $block->toHtml();exit;
}
view.phtml page in template
Replace above code To below code
productAddToCartForm.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
if(!url){
url = jQuery('#product_addtocart_form').attr('action');
}
var data = jQuery('#product_addtocart_form').serialize();
data += '&isAjax=1';
try {
jQuery('.product-shop').prepend('<div class="ajax_loader"> </div>');
jQuery.ajax({
url: url,
dataType: 'json',
type : 'post',
data: data,
success: function(data){
getcartdata(this);
}
});
setTimeout(function(){
getcartdata(this.form);
},1000);
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}
}
}.bind(productAddToCartForm);
Write Bottom in view page
<script type="text/javascript">
function getcartdata($this){
jQuery.ajax( {
url : "<?php echo Mage::getBaseUrl().'getcitys/index/getcartdetail'; ?>",
dataType : 'html',
type : 'get',
success : function(data) {
jQuery('.ajax_loader').hide();
jQuery('.block-cart-header').html(data);
}
});
}
</script>
<form class="product_addtocart_form" action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if(!$_product->isGrouped()): ?>
<label for="qty" class="qtylabel" style=""><?php echo $this->__('Qty') ?>:</label>
<input type="text" class="form-control qtybox" name="qty">
<?php endif; ?>
<button type="submit" class="link_cart"><span><i class="fa fa-shopping-cart" style="margin-right: 5px;"></i><?php echo $this->__('Add to Cart') ?></span></button>
</form>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('.product_addtocart_form').submit(function(event){
event.preventDefault();
var $this = jQuery(this);
jQuery($this).parents('li').append('<div class="ajax_loader"></div>');
url = jQuery(this).attr('action');
console.log(jQuery(this).serialize());
url += '&isAjax=1';
var data = jQuery(this).serialize();
data += '&isAjax=1';
jQuery.ajax({
url : url,
dataType : 'json',
type : 'post',
data : data,
success : function(data) {
getcartdata($this);
}
});
setTimeout(function(){
//getcartdata($this);
},1000);
});
});
function getcartdata($this){
jQuery.ajax( {
url : "<?php echo Mage::getBaseUrl().'getcitys/index/getcartdetail'; ?>",
dataType : 'html',
type : 'get',
success : function(data) {
jQuery('.ajax_loader').hide();
jQuery('.block-cart-header').html(data);
}
});
}
</script>
Make in controllers/IndexController.php
public function getcartdetailAction() {
$block = $this->getLayout()->createBlock('checkout/cart_sidebar');
$block->setTemplate('checkout/cart/sidebar_header_ajax.phtml');
echo $block->toHtml();exit;
}
view.phtml page in template
productAddToCartForm.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
try {
this.form.submit();
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}
if (button && button != 'undefined') {
button.disabled = true;
}
}
}.bind(productAddToCartForm);
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
try {
this.form.submit();
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}
if (button && button != 'undefined') {
button.disabled = true;
}
}
}.bind(productAddToCartForm);
Replace above code To below code
productAddToCartForm.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
if(!url){
url = jQuery('#product_addtocart_form').attr('action');
}
var data = jQuery('#product_addtocart_form').serialize();
data += '&isAjax=1';
try {
jQuery('.product-shop').prepend('<div class="ajax_loader"> </div>');
jQuery.ajax({
url: url,
dataType: 'json',
type : 'post',
data: data,
success: function(data){
getcartdata(this);
}
});
setTimeout(function(){
getcartdata(this.form);
},1000);
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}
}
}.bind(productAddToCartForm);
Write Bottom in view page
<script type="text/javascript">
function getcartdata($this){
jQuery.ajax( {
url : "<?php echo Mage::getBaseUrl().'getcitys/index/getcartdetail'; ?>",
dataType : 'html',
type : 'get',
success : function(data) {
jQuery('.ajax_loader').hide();
jQuery('.block-cart-header').html(data);
}
});
}
</script>
Wednesday, 19 August 2015
How to import database using ubuntu terminal or windwos CMD
For linux ubunto
pv /var/www/html/decorati_main.sql.gz | gunzip | mysql -u root -p root
apt-get install pv
pv /var/www/html/decorati_main.sql.gz | gunzip | mysql -u root -p decorativeplumb
For Windows
mysql -uroot -ppassword mydb > myfile.sql.gz
Subscribe to:
Posts (Atom)