ستساعدك المقالة التالية: كيفية تصدير منتجات Magento في ملف XML
<؟ php
تتطلب “app / Mage.php” ؛
ماجى :: التطبيق () ؛
$ storename = “افتراضي” ؛
ملف $ = “products-top10.xml” ؛
إذا (file_exists ($ file)) {
فك الارتباط (ملف $) ؛
}
يحاول {
منتجات $ = Mage :: getModel (“كتالوج / منتج”)
-> getCollection ()
-> addAttributeToSelect (‘*’)
-> setPageSize (200)
-> setCurPage (1)
-> setOrder (‘id’، ‘ASC’)
-> addAttributeToFilter (‘الحالة’ ، المصفوفة (‘eq’ => ‘1’)) ؛
$ doc = new DOMDocument () ؛
$ doc-> ترميز = ‘utf-8’ ؛
$ doc-> formatOutput = صحيح ؛
$ root = $ doc-> createElement (“root”) ؛
$ doc-> appendChild ($ root) ؛
$ productsX = $ doc-> createElement (“كتالوج”) ؛
$ root-> appendChild ($ productsX) ؛
foreach ($ products as $ _product) {
$ product = $ doc-> createElement (“منتج”) ؛
$ id = $ doc-> createElement (“id”)؛
$ id-> appendChild (
$ doc-> createTextNode ($ _ product-> getId ())
) ؛
$ product-> appendChild ($ id) ؛
$ url = $ doc-> createElement (“url”) ؛
$ url-> appendChild (
$ doc-> createTextNode (تقليم ($ _ product-> getData (‘url_key’)))
) ؛
$ product-> appendChild ($ url) ؛
$ urlPath = $ doc-> createElement (“url_path”) ؛
$ urlPath-> appendChild (
$ doc-> createTextNode (تقليم ($ _ product-> getProductUrl ()))
) ؛
$ product-> appendChild ($ urlPath) ؛
$ title = $ doc-> createElement (“title”)؛
$ title-> appendChild (
$ doc-> createTextNode (تقليم ($ _ product-> getName ()))
) ؛
$ product-> appendChild ($ title)؛
$ sku = $ doc-> createElement (“sku”)؛
$ sku-> appendChild (
$ doc-> createTextNode ($ _ product-> getSku ())
) ؛
$ product-> appendChild ($ sku) ؛
$ price = $ doc-> createElement (“السعر”) ؛
السعر $-> appendChild (
$ doc-> createTextNode (تقليم ((int) $ _ product-> getPrice ()))
) ؛
المنتج $-> appendChild (السعر بالدولار) ؛
$ formatedprice = $ doc-> createElement (“formated_price”)؛
$ formattedPrice = Mage :: helper (‘core’) -> العملة ($ _ product-> getPrice ()، true، false)؛
سعره $ formated-> appendChild (
$ doc-> createTextNode (تقليم ($ formattedPrice))
) ؛
$ product-> appendChild ($ formatedprice)؛
$ productsX-> appendChild ($ product) ؛
}
file_put_contents (ملف $ ، $ doc-> saveXML () ، FILE_APPEND) ؛
} catch (استثناء $ e) {
صدى “خطأ: -” ؛
صدى $ e-> getMessage () ؛
}