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

时间:2018-09-26 06:48:35

标签: javascript php ajax magento-1.9.2.1

我想将产品从一种类别转移到另一种。它正在工作,但是要花费很多时间,或者您可以说这很耗时。 紧记,移动产品意味着从现有类别中删除该产品。 通过移动 6 产品,需要3.6分钟,这对任何开发人员都不利。如果有人是恢复时间复杂度的专家,请提供帮助。

**PHP CODE IS HERE...**
<?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;
?>

$(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 FIRE HERE**

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

    });

1 个答案:

答案 0 :(得分:0)

您为什么不尝试通过CSV。快速简便: Move products