Showing posts with label Add. Show all posts
Showing posts with label Add. Show all posts

Thursday 26 October 2023

Shopify - Add dynamic links on description

{% assign productdescription = product.description %}

{% assign productdesclinks = "maxi dress~https://examples.com/collections/maxi-dresses,midi dress~https://examples.com/collections/midi-length-dresses,midi~https://examples.com/collections/midi-length-dresses,pockets~https://examples.com/collections/dresses-with-pockets,kasey rainbow~https://examples.com/collections/kasey-rainbow,maggi~https://examples.com/collections/maggi-mcdonald-x-proud-poppy ,Maggi McDonald~https://examples.com/collections/maggi-mcdonald-x-proud-poppy,spring~https://examples.com/collections/spring-dresses-collection ,floral~https://examples.com/collections/floral-dresses" %}

{% assign productdesclinks = productdesclinks | split: ',' %}

{% for productdesclink in productdesclinks %}

  {% assign productdesclk = productdesclink | split: '~' %}

  {% assign productdesclkcomp = productdesclk[0] %}

  {% assign productdesclkurl = productdesclk[1] %}

  {% assign productdesclklink = '<a href="' | append: productdesclkurl | append: '">' | append: productdesclkcomp | append:"</a>" %}

  {% assign productdescription = productdescription | replace:productdesclkcomp, productdesclklink %}

{% endfor %}

{{ productdescription }} 




Friday 4 October 2019

Cannot add a new addondomain in WHM panel

(XID a57bw8) Sorry, the domain is already pointed to an IP address that does not appear to use DNS servers associated with this server. in WHM panel

Visit this area in WHM panel:

1. WebHost Manager »Server Configuration »Tweak Settings, Domains tab:

2. Enable the following setting


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

Friday 9 February 2018

How to add / create grid Tab in custom module in magento admin panel

Step1 :
open : /app/code/local/Namespace/Modulename/Block/Adminhtml/Employee/Edit/Tabs.php
Add following lines

protected function _beforeToHtml()
{
.........
.........
.........
$this->addTab(
    'form_advancepayment',
    array(
'label'   => Mage::helper('namespace_modulename')->__('Advance Payment'),
'title'   => Mage::helper('namespace_modulename')->__('Advance Payment'),
'content' => $this->getLayout()->createBlock(
    'namespace_modulename/adminhtml_employee_edit_tab_advancepayment'
)
->toHtml(),
    )
);
return parent::_beforeToHtml();
}
Step2 :
Create new file (Advancepayment.php) : /app/code/local/Namespace/Modulename/Block/Adminhtml/Employee/Edit/Tab/Advancepayment.php
<?php
class Namespace_Modulename_Block_Adminhtml_Employee_Edit_Tab_Advancepayment extends Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
        parent::__construct();
        $this->setId('advancepymt_grid');
        $this->setDefaultSort('entity_id');
        $this->setDefaultDir('DESC');
        $this->setSaveParametersInSession(true);
        $this->setUseAjax(true);
        //$this->setFilterVisibility(false);
    }
   
    protected function _prepareCollection()
    {
        $id = $this->getRequest()->getParam('id');
        $collection = Mage::getModel('namespace_modulename/advancepymt')
            ->getCollection()
            ->addFieldToFilter('employee_id', $id);
       
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }
   
    protected function _prepareColumns()
    {
        $this->addColumn(
            'entity_id',
            array(
                'header' => Mage::helper('namespace_modulename')->__('Id'),
                'index'  => 'entity_id',
                'filter' => false,
                'type'   => 'number'
            )
        );
        $this->addColumn(
            'payment',
            array(
                'header'    => Mage::helper('namespace_modulename')->__('Payment'),
                'align'     => 'left',
                'type'   => 'number',
                'index'     => 'payment',
            )
        );
       
        $this->addColumn(
            'created_at',
            array(
                'header' => Mage::helper('namespace_modulename')->__('Created at'),
                'index'  => 'created_at',
                'width'  => '120px',
                'type'   => 'datetime',
            )
        );
        return parent::_prepareColumns();
    }
   
    public function getGridUrl()
    {
        return $this->getUrl('*/*/advancepymt', array('_current'=>true));
    }
   
    public function getRowUrl($row)
    {
        return $this->getUrl('*/*/edit', array('id' => $row->getId()));
    }
Step3 :
Create function in current controller : /app/code/local/Namespace/Modulename/controllers/Adminhtml/Payroll/EmployeeController.php
class Namespace_Modulename_Adminhtml_Payroll_EmployeeController extends Namespace_Modulename_Controller_Adminhtml_Payroll
{
.............
.............
.............
public function advancepymtAction() {
        $this->loadLayout();
        $this->getLayout()->getBlock('edit.tab.advancepayment');
        $this->renderLayout(); 
    }
Step4 :
Add view in admin layout xml file : /app/design/adminhtml/default/default/layout/namespace_modulename.xml
Add following code into file

...........
...........
<adminhtml_modulename_employee_advancepymt>
<block type="core/text_list" name="root" output="toHtml">
    <block type="namespace_modulename/adminhtml_employee_edit_tab_advancepayment" name="edit.tab.advancepayment"/>
</block>
</adminhtml_modulename_employee_advancepymt>
...........
........... 

Thursday 22 September 2016

Adding an existing project to GitHub /Bitbucket using the command line

1. Create a new repository on GitHub. To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can add these files after your project has been pushed to GitHub.

2. Open Terminal.

3. Change the current working directory to your local project.

4. Initialize the local directory as a Git repository.
    $ git init

5. Add the files in your new local repository. This stages them for the first commit.
    $ git add .
    # Adds the files in the local repository and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'.

6. Commit the files that you've staged in your local repository.
    $ git commit -m "First commit"
    # Commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.

7. At the top of your GitHub repository's Quick Setup page, click to copy the remote repository URL.

8. In Terminal, add the URL for the remote repository where your local repository will be pushed.
    $ git remote add origin remote repository URL
    # Sets the new remote
    $ git remote -v
    # Verifies the new remote URL

9. Push the changes in your local repository to GitHub.
    $ git push origin master
    # Pushes the changes in your local repository up to the remote repository you specified as the origin

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>