繁体   English   中英

在 Magento 1.9.2 中以编程方式将类别项目或产品移动到另一个类别需要大量时间

[英]Moving category items or products to another category taking a lot of time in Magento 1.9.2 programmatically

我想将产品从一个类别转移到另一个类别。 它正在工作,但要花很多时间,或者你可以说它很耗时。 请记住,移动产品意味着从现有类别中删除该产品。 移动6 个产品需要 3.6 分钟,这对任何开发人员都不利。

PHP:

<?php
set_time_limit(0);
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
// Load Magento
require_once '../../app/Mage.php';
Mage::app();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

if(isset($_POST['removeitems']))
{
    $categoryId = $_POST['catid']; 
    $movefromcat = $_POST['movefrom'];
    $items = $_POST['removeitems'];
    $items = explode(',',$items);

    foreach($items as $item){
        
         $product = Mage::getModel('catalog/product')->load($item);
         
         $product->setCategoryIds(
            array_merge($product->getCategoryIds(), array($categoryId))
         );
         
          $product->save();
         Mage::getSingleton('catalog/category_api')->removeProduct($movefromcat,$item);
    }
    
    echo json_encode(array('msg' => 'Products moved to category id: '.$categoryId.' successfully!'));
}
   exit;
?>

JavaScript:

$(document).on("click","#movetoanothercategory",function(){

        $(".removecategoryproducts").hide();
            $("input.itemtomoveOrCopy").each(function(){
                $('.itemtomoveOrCopy').remove(); 
            });

            $(".hideme").hide();

        if(tipstatus.enable > 0){
            alert(tips.movecategoryitem);
        }
        if($("#categoryselect").val() == "" || $("#categoryselect").val() == "0"){
            alert("Load product from any category first");
            return false;
        }
        if ($('input#movetoanothercategory').prop('checked')) {
            $(".hideme").show(); 
            $(".copytocategory").hide();
            $(".submitmoveitems").show();
            
            $("#simpleList>.improduct").each(function(){
                var itid = $(this).attr('id');
                $(this).children('div.thumbnail').each(function(i){
                   // $(this).children(".checkbox"); 
                    $(this).prepend("<input type='checkbox' class='itemtomoveOrCopy' attr-id='"+itid+"'>");
                });
            });
        }else{
            $(".hideme").hide();
            $(".submitmoveitems").hide();
            $("input.itemtomoveOrCopy").each(function(){
                $(this).remove(); 
            });
        }
        
    });

AJAX 在这里触发:

$.ajax({
    method: "post",
    url: "movetoanothercategory.php",
    data: "removeitems="+items+"&catid="+Movetocat+"&movefrom="+$.trim($("#categoryselect").val()),
    dataType:"json",
    cache:false,
    success:function(rt){
        alert(rt.msg);
        $.unblockUI();
        $(".loadcategoryitems").click();
    }
});

你为什么不尝试通过 CSV。 快速简单: 移动产品

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM