我需要在XML源中创建Magento中的订单,订单在Magento中放置精细,但购物车规则不正确申请。 CART规则不会在每篇文章中应用折扣。如果我检查每个项目中应用的规则,我可以看到ID规则应用于项目,但折扣不会出现。

如果我使用magento管理员手动制作相同的订单,购物车规则完美地适用。

代码处理目录中的所有.xml文件并将它们移动到已处理的目录。

require_once '../../app/Mage.php';
Mage::app();

ini_set('xdebug.var_display_max_depth', 10);
ini_set('xdebug.var_display_max_children', 256);
ini_set('xdebug.var_display_max_data', 1024);


//$archivos  = scandir('D:\FTP\COM\XMLPendientes');
$archivos  = array_diff(scandir('D:\FTP\COM\XMLPendientes'), array('..', '.'));

foreach($archivos as $archivo)
{
    echo '<p>****** '.date("Ymd-His").' Procesando '.$archivo.' *****';
    $ProcesadoOk = ProcesarXML('D:\FTP\COM\XMLPendientes\\'.$archivo);
    echo '<br>Procesado D:\FTP\COM\XMLPendientes\\'.$archivo.' Pedido '.$ProcesadoOk;
    rename('D:\FTP\COM\XMLPendientes\\'.$archivo, 'D:\FTP\COM\XMLEnviados\\'.$archivo);
    echo '<br>Movido D:\FTP\COM\XMLPendientes\\'.$archivo, ' --> D:\FTP\COM\XMLEnviados\\'.$archivo;
}

$fp = fopen("registro.html", "a");
$data = ob_get_contents();
//$data = ob_get_clean();
fwrite($fp, $data);
fclose($fp); 

//$ProcesadoOk = ProcesarXML('D:\FTP\COM\XMLPendientes\003089-07092015155055.xml');

function ProcesarXML($archivo)
{ 
    $pedido = simplexml_load_file($archivo);
    //var_dump($archivo);
    // Obtener ID cliente
    //$query = "000071X";
    //var_dump($pedido);
    $query = $pedido->Cliente[0]->Codigo;
    echo '<br>Asociado Cod Ccp: '.$query;
    $model = Mage::getSingleton('customer/customer');
    $result = $model->getCollection()
            ->addAttributeToSelect('*')
            ->addAttributeToFilter('codigo_ccp', array('like' => "%$query%"))
            ->addAttributeToFilter('website_id', array('like' => "1"));
    foreach($result as $r) 
    {       
            $customer = $model->load($r->getId());
            echo '<br>Nombre: '.$customer->getFirstname().' Nombre 2: '.$customer->getLastname();
            $customerId = $customer->getId();
            echo '<br>Asociado Magento ID: '.$customerId;
    }
    // FIN Obtener ID cliente


    $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore('default')->getId());

    // for customer orders:
    $customer = Mage::getModel('customer/customer')->setWebsiteId(1)->load($customerId);
    $quote->assignCustomer($customer);



    // add product(s)
    //$product = Mage::getModel('catalog/product')->load(140268);

    foreach ($pedido->Detalle[0]->Articulo as $item)
    {
        if ($item->Qty != '0') {
            //$sku = $item->Sku;
            //$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
            //$product = Mage::getModel('catalog/product')->load($product->getId());

            $product = Mage::getModel('catalog/product')->load($item->Id);
            echo '******************************PRODUCTO********************';
            var_dump($product);

            $buyInfo = array(
                    'qty' => (string)$item->Qty,
                    //añado (string) por error Uncaught exception 'Exception' with message 'Serialization of 'SimpleXMLElement' is not allowed'
                    // custom option id => value id
                    // or
                    // configurable attribute id => value id
            );
            echo '<br>ID: '.$product->getId().' Sku: '.$item->Sku.' Qty: '.$item->Qty;
            $quote->addProduct($product, new Varien_Object($buyInfo));
        }
    }

    $addressData = array(
            'firstname' => $customer->getFirstname(),
            'lastname' => $customer->getLastname(),
            'street' => $pedido->ID,
            'city' => 'Ciudad',
            'postcode' => '123456',
            'telephone' => '123456',
            'country_id' => 'ES',
            'region_id' => 12, // id de la tabla directory_country_region
    );

    $billingAddress = $quote->getBillingAddress()->addData($addressData);
    $shippingAddress = $quote->getShippingAddress()->addData($addressData);

    $shippingAddress->setCollectShippingRates(true)->collectShippingRates()
                    ->setShippingMethod('flatrate_flatrate')
                    ->setPaymentMethod('banktransfer');


    $quote->getPayment()->importData(array('method' => 'banktransfer'));

    $quote->pedido_comercial = 'ProcesadoCOM';
    $quote->pedido_usuario = 'ComercialX'; 

    echo '******************************QUOTE BEFORE COLLECTTOTALS********************';
    var_dump($quote);
    $quote->collectTotals()->save(); 
    echo '******************************QUOTE AFTHER COLLECTTOTALS********************';
    var_dump($quote);

    // $quote->setTotalsCollectedFlag(false)->collectTotals()->save(); //ERROR no vale

    //Probando esto: No funciona
    //$convertQuote = Mage::getSingleton('sales/convert_quote'); 
    //$order = $convertQuote->toOrder($quote); 

    $service = Mage::getModel('sales/service_quote', $quote);
    $service->submitAll();
    echo '******************************SERVICE****************************************';
    var_dump($service);
    $order = $service->getOrder();
    echo '******************************ORDER****************************************';
    var_dump($order);

    $order = $order->setPedidoComercial("ProcesadoCOM");
    $order = $order->setPedidoUsuario("ComercialX");
    $order->addStatusHistoryComment($pedido->Observaciones);
    $order->addStatusHistoryComment('COM '.$pedido->ID);
    //$order->addStatusHistoryComment('Pedido de Prueba. NO PROCESAR');

    //Pruebas reglas carrito
    //$order->collectTotals()->save(); //ERROR no vale
    //Fin Pruebas reglas carrito

    $order->save();

    //printf("Creado pedido %s\n", $order->getIncrementId());

    return $order->getIncrementId();
}
.

检查此订单屏幕捕获:

i simbol向我展示在每个项目中应用了哪些规则,您可以在Item Maw1280590中看到我有:

SFS周末全周套规则应用,它必须在MAW开头的物品惠特SKU上提供10%的折扣。不要申请折扣,但出现在适用于项目的规则中。

Ti22 12 + 2 PLV规则应用,此规则为带有MTI开始的SKU的所有物品添加免费礼品。此项目不匹配规则但正在应用。

使用类别的项目类别来检查是否必须适用。

当我在magento / admin中创建订单时,有时我必须单击“更新项目和Qty”以查看正确的所有规则。有没有办法以编程方式处理“更新项目和数量”?

任何想法?谢谢!!

添加:

我尝试一些代码修改,但没有运气....

//Prueba ME DEJA TODO EL PEDIDO A CERO. ERROR ALL PRICES TO ZERO
    /*
    $items = $quote->getAllVisibleItems();
    foreach($items as $item)
    {
        $item->setCustomPrice(0);
        $item->setOriginalCustomPrice(0);
        $item->getProduct()->setIsSuperMode(true);
        $item->save();
    }
    $quote->save();
    $quote->setTotalsCollectedFlag(false)->collectTotals();
    */
    //Fin Prueba

    //Prueba 2 IGUAL, NO APLICA LOS DESCUENTOS. ERROR, DONT APPLY DISCOUNTS.
    /*
    $quote->setTotalsCollectedFlag(false);
    $quote->getShippingAddress()->unsetData('cached_items_all');
    $quote->getShippingAddress()->unsetData('cached_items_nominal');
    $quote->getShippingAddress()->unsetData('cached_items_nonnominal');
    $quote->collectTotals();
    */
    //Fin Prueba 2

    //Prueba 3 IGUAL, NO APLICA LOS DESCUENTOS. ERROR, DONT APPLY DISCOUNTS.
    //$cart = Mage::getSingleton('checkout/session')->getQuote();
    /*
    foreach ($quote->getAllAddresses() as $address)
    {
        $address->unsetData('cached_items_nonnominal');
        $address->unsetData('cached_items_nominal');
    }
    $quote->setTotalsCollectedFlag(false);
    $quote->collectTotals();
    */
    //Fin Prueba 3
.

帮助!! :)

新信息:

测试规则,我们发现只有Magento Connect的Amasty Special Prompion Pro模块所做的规则。我们与Anasty联系以获得帮助。

有帮助吗?

解决方案

没办法。不可能将其与Amasty Themicing Propportion Pro模块一起工作。

许可以下: CC-BY-SA归因
scroll top