Showing posts with label URL. Show all posts
Showing posts with label URL. Show all posts

Wednesday 19 September 2018

How to change url without reloading page in jQuery | Javascript | PHP

<?php
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$lastchar = substr($actual_link, -1);
if($lastchar == '/'){
$redirecturl = rtrim($actual_link,"/");
?>
<script>
    window.history.pushState('page2', 'Title', '<?php echo $redirecturl; ?>');
</script>
<?php } ?>

Saturday 23 June 2018

How to Import / Insert / Add product image from URL in Magento 2

use Magento\Framework\App\Action\Context;

class Createproduct extends \Magento\Framework\App\Action\Action {

    protected $directoryList;
    protected $file;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $pageFactory,
        \Magento\Framework\App\Filesystem\DirectoryList $directoryList,
        \Magento\Framework\Filesystem\Io\File $file) {

        $this->_resultpageFactory = $pageFactory;
        $this->directoryList = $directoryList;
        $this->file = $file;
        return parent::__construct($context);
    }


    protected function getMediaDirTmpDir()
    {
        return $this->directoryList->getPath($this->directoryList::MEDIA) . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
    }

    public function setImage($product, $imageUrl, $visible = false, $imageType = [])
    {
        $tmpDir = $this->getMediaDirTmpDir();

        $this->file->checkAndCreateFolder($tmpDir);

        $newFileName = $tmpDir . baseName($imageUrl);


        $result = $this->file->read($imageUrl, $newFileName);
        if ($result) {
            $product->addImageToMediaGallery($newFileName, $imageType, true, $visible);
        }
        return $result;
    }

    public function execute() {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $product = $objectManager->create('\Magento\Catalog\Model\Product')->load(1);
        $imagePath = "https://domain.com/image.jpg"; // path of the image
            $this->setImage($product, $imagePath, false, $imageType = ['image', 'small_image', 'thumbnail']);
            $product->save();
    }
}

Wednesday 21 September 2016

How to get a url parameter in Magento controller?

Is there a Magento function to get the value of "id" from this url:

http://domain.com/path/action/id/123

$id = $this->getRequest()->getParam('id', 0);

Tuesday 13 September 2016

How to Check URL is Secure or Not in amazon EC2 Server in PHP / Codeigniter SSL

You can use following code for  Check URL is Secure or Not in amazon EC2 Server


if ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
      $_SERVER['HTTPS'] = 'on';
} else {
      $_SERVER['HTTPS'] = 'off';
}

Monday 6 June 2016

How to run URL Using exec, Shell_exec in php

function testf(){
        $url = 'http://www.google.com';
        $outputfile = "jems.html";
        $cmd = "wget -q \"$url\" -O $outputfile";
        exec($cmd);
        echo file_get_contents($outputfile);
    }

Monday 16 May 2016

How to check my url is in iframe or not javascript

Browsers can block access to window.top due to same domain.

Example

<script>
inIframe();
function inIframe () {
    try {
        var isif = window.self !== window.top;
        if(isif == false){
            //not iframe
        }else{
  //in iframe
}
    } catch (e) {
            //not iframe
    }
}
</script>

top and self are both window objects (along with parent), so you're seeing if your window is the top window.

Friday 29 April 2016

Adding products to cart via url in magento

If your Planning to do a website that opens directly on the cart page, in the cart it needs to have some products already selected and it should be ready to go to the checkout page.

Every time the user goes to the page, some products.

<a href="http://example.com/index.php/checkout/cart/add/product/1/form_key/<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>/">My cart</a>

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();

Friday 26 June 2015

CodeIgniter Remove index.php from URL

change in .htaccess file and try it

RewriteEngine OnRewriteBase /project/RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Friday 9 August 2013

Custom search engine friendly (SEF) URL In Magento.


Custom SEF helper method

class <Namespace>_<Module>_Helper_Data extends Mage_Core_Helper_Abstract
{
function custom_sef_url($id_path, $request_path, $target_path, $store_id ="0", $is_system=false){
$isrewrite = Mage::getModel('core/url_rewrite')->load($id_path,id_path);
    if($isrewrite->url_rewrite_id !=""){
      throw new Exception("Your Id path must be unique, given id path already in use !");
    }
      $rewrite = Mage::getModel('core/url_rewrite');
      $rewrite->setStoreId($store_id)
        ->setIdPath($id_path)
        ->setRequestPath($request_path)
        ->setTargetPath($target_path)
        ->setIsSystem($is_system)
        ->save();       
return;
}
}

Where should I call Custom SEF helper method?

Normally we need to create the custom URL once the new item is created, so we need to call this method in your “saveAction()” function after saving process. Let’s take FAQ items as example.

public function saveAction()
{

// .... faq saving process

try{
  $id_path = "faq/".$id;  // Id path must be unique
  $request_path = "fag/".$fag_title;
  $target_path  = "fag/index/index/id/".$id;

   Mage::helper('<module>')-&gt;custom_sef_url($id_path, $request_path, $target_path);
}
catch (Exception $e) {

 Mage::getSingleton('adminhtml/session')-&gt;addError($e-&gt;getMessage());

}

}

Saturday 26 May 2012

Get URL With Id ex : id="1500" in Joomla

JRequest::getVar

<?php $itemid = JRequest::getVar('Itemid');
if($itemid == '50')
{
    echo '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>';

}
?>