Example #1
0
 protected function setUp()
 {
     \Mage::init();
     $this->mink = new Mink(array('goutte' => new Session(new GoutteDriver())));
     $this->mink->setDefaultSessionName('goutte');
     $this->manager = new FixtureManager(new AttributesProvider());
 }
Example #2
0
 public static function createOrder($order, $product)
 {
     Mage::init();
     $customer = Mage::getModel('customer/customer')->load($order['customer_id']);
     $transaction = Mage::getModel('core/resource_transaction');
     $store_Id = $customer->getStoreId();
     //$order = Mage::getModel("sales/order")->getCollection()->getLastItem()->getIncrementId();
     $lastOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($store_Id);
     //$lastOrderId = $order->getIncrementId();
     $order = Mage::getModel('sales/order')->setIncrementId($lastOrderId)->setStoreId($store_Id)->setQuoteId(0)->setGlobal_currency_code('CNY')->setBase_currency_code('CNY')->setStore_currency_code('CNY')->setOrder_currency_code('CNY')->setOrigin_order_id($order['origin_order_id'])->setReferer($order['referer'])->setTo_buyer($order['to_buyer'])->setIs_1yuan($order['is_1yuan'])->setDevice_id($order['device_id'])->setShipping_type($order['shipping_type'])->setCreated_at($order['create_at']);
     $order->setCustomer_email($customer->getEmail())->setCustomerFirstname($customer->getFirstname())->setCustomerLastname($customer->getLastname())->setCustomerGroupId($customer->getGroupId())->setCustomer_is_guest(0)->setCustomer($customer);
     $billing = $customer->getDefaultBillingAddress();
     $billingAddress = Mage::getModel('sales/order_address')->setStoreId($store_Id)->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING)->setCustomerId($customer->getId())->setCustomerAddressId($customer->getDefaultBilling())->setCustomer_address_id($billing->getEntityId())->setPrefix($billing->getPrefix())->setFirstname($billing->getFirstname())->setMiddlename($billing->getMiddlename())->setLastname($billing->getLastname())->setSuffix($billing->getSuffix())->setCompany($billing->getCompany())->setStreet($billing->getStreet())->setCity($billing->getCity())->setCountry_id($billing->getCountryId())->setRegion($billing->getRegion())->setRegion_id($billing->getRegionId())->setPostcode($billing->getPostcode())->setTelephone($billing->getTelephone())->setFax($billing->getFax());
     $order->setBillingAddress($billingAddress);
     $shipping = $customer->getDefaultShippingAddress();
     $shippingAddress = Mage::getModel('sales/order_address')->setStoreId($store_Id)->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)->setCustomerId($customer->getId())->setCustomerAddressId($customer->getDefaultShipping())->setCustomer_address_id($shipping->getEntityId())->setPrefix($shipping->getPrefix())->setFirstname($shipping->getFirstname())->setMiddlename($shipping->getMiddlename())->setLastname($shipping->getLastname())->setSuffix($shipping->getSuffix())->setCompany($shipping->getCompany())->setStreet($shipping->getStreet())->setCity($shipping->getCity())->setCountry_id($shipping->getCountryId())->setRegion($shipping->getRegion())->setRegion_id($shipping->getRegionId())->setPostcode($shipping->getPostcode())->setTelephone($shipping->getTelephone())->setFax($shipping->getFax());
     $order->setShippingAddress($shippingAddress)->setShipping_method('flatrate_flatrate');
     $orderPayment = Mage::getModel('sales/order_payment')->setStoreId($store_Id)->setCustomerPaymenyId(0)->setMethod('purchaseorder')->setPo_number(' - ');
     $order->setPayment($orderPayment);
     $subTotal = 0;
     $products = array('2' => array('qty' => 2));
     foreach ($products as $productId => $product) {
         $_product = Mage::getModel('catalog/product')->load($productId);
         $rowTotal = $_product->getPrice() * $product['qty'];
         $orderItem = Mage::getModel('sales/order_item')->setStoreId($store_Id)->setQuoteItemId(0)->setQuoteParentItemId(NULL)->setProductId($productId)->setProductType($_product->getTypeId())->setQtyBackordered(NULL)->setTotalQtyOrdered($product['qty'])->setQtyOrdered($product['qty'])->setName($_product->getName())->setSku($_product->getSku())->setPrice($_product->getPrice())->setBasePrice($_product->getPrice())->setOriginalPrice($_product->getPrice())->setRowTotal($rowTotal)->setBaseRowTotal($rowTotal);
         $subTotal += $rowTotal;
         $order->addItem($orderItem);
     }
     $order->setSubtotal($subTotal)->setBaseSubtotal($subTotal)->setGrandTotal($subTotal)->setBaseGrandTotal($subTotal);
     $transaction->addObject($order);
     $transaction->addCommitCallback(array($order, 'place'));
     $transaction->addCommitCallback(array($order, 'save'));
     $transaction->save();
 }
Example #3
0
 public function run()
 {
     // Switch to some specific store view
     Mage::init();
     // Initialize area (<frontend> configuration nodes under modules config.xml)
     Mage::app()->loadArea(Mage_Core_Model_App_Area::AREA_FRONTEND);
     // Add some rewrite
     Mage::app()->getConfig()->setNode('global/models/catalog/rewrite/product', 'Catalog_Product_Debug');
     // Echo 'It works!'
     Mage::getModel('catalog/product')->testDebugMethod();
 }
 public function testGenerateUniqueId()
 {
     Mage::init();
     $payment = new Varien_Object();
     $order = new Varien_Object();
     $billingAddress = new Varien_Object();
     $order->setBillingAddress($billingAddress);
     $payment->setOrder($order);
     $litle = new Litle_CreditCard_Model_PaymentLogic();
     $mock = $this->getMock('Mage_Payment_Model_Info');
     $hash = $litle->generateAuthorizationHash('123', '100', $mock, $payment);
     $this->assertEquals('123', $hash['id']);
 }
function bootstrap()
{
    /**
     * Error reporting
     */
    error_reporting(E_ALL | E_STRICT);
    $mageFilename = 'app/Mage.php';
    $maintenanceFile = 'maintenance.flag';
    require_once $mageFilename;
    #Varien_Profiler::enable();
    Mage::setIsDeveloperMode(true);
    ini_set('display_errors', 1);
    umask(0);
    /* Store or website code */
    $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
    /* Run store or run website */
    $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
    if (method_exists('Mage', 'init')) {
        Mage::init($mageRunCode, $mageRunType);
    } else {
        Mage::app($mageRunCode, $mageRunType);
    }
    return $mageFilename;
}
Example #6
0
<?php

include_once 'app/Mage.php';
Mage::init();
//Initializing PHP variable with string
$captchanumber = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz';
//Getting first 6 word after shuffle
$captchanumber = substr(str_shuffle($captchanumber), 0, 6);
//Initializing session variable with above generated sub-string
//$_SESSION["code"] = $captchanumber;
$session = Mage::getSingleton("core/session", array("name" => "frontend"));
$session->setData("catptchacode", trim($captchanumber));
//Mage::getSingleton('core/session')->setCaptchacode($captchanumber);
//Generating CAPTCHA
$image = imagecreatefromjpeg("bj.jpg");
$foreground = imagecolorallocate($image, 0, 0, 0);
//font color
imagestring($image, 20, 35, 12, $captchanumber, $foreground);
header('Content-type: image/png');
imagepng($image);
Example #7
0
    public static function displayAttributeManagementTool()
    {
        global $b2b, $db, $client, $sessionId;
        Mage::init();
        $Magento_AttributeSets = array();
        $attributestmp = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getAttributeCollection();
        foreach ($attributestmp->getData() as $at) {
            // if (substr($at['attribute_code'], 0, strlen(ATTRIBUTES_PREFIX) ) == ATTRIBUTES_PREFIX) {
            $Magento_Attributes[$at['attribute_code']]['attribute_id'] = $at['attribute_id'];
            $Magento_Attributes[$at['attribute_code']]['name'] = $at['frontend_label'];
            // }
        }
        ksort($Magento_Attributes);
        $Magento_AttributeSets_temp = $client->call($sessionId, "catalog_product_attribute_set.list");
        foreach ($Magento_AttributeSets_temp as $as) {
            $Magento_AttributeSets[$as['name']] = $as['set_id'];
        }
        echo '<table border="0" cellpadding="0" cellspacing="0" width="600">';
        foreach ($Magento_Attributes as $Magento_Attribute) {
            if ($Magento_Attribute['name'] == "") {
                continue;
            }
            echo "<tr>";
            echo "<td>{$Magento_Attribute['name']}</td>";
            echo "<td>{$Magento_Attribute['code']}</td>";
            echo "<td><span class='copy_to_all_sets' id_attribute='{$Magento_Attribute['attribute_id']}'>COPY to all Sets</span></td>";
            echo "<td><span class='remove_from_all_sets' id_attribute='{$Magento_Attribute['attribute_id']}'>REMOVE from all Sets</span></td>";
            echo "</tr>";
        }
        echo '</table>';
        //  dump($Magento_AttributeSets);
        // dump($Magento_Attributes);
        ?>
       <style>
       .copy_to_all_sets{text-decoration: underline; color:blue;cursor:pointer}
       .remove_from_all_sets{text-decoration: underline; color:blue;cursor:pointer}
       </style><script language="JavaScript">
        <!--
          jQuery('.copy_to_all_sets').click(function() {
          	  	var e = $(this);
          	  	id_attribute = e.attr("id_attribute");
				var data = {  'supplier': supplier, 'id_attribute': id_attribute, 'to_do': "COPY_TO_ALL_SETS" };
				$.ajax({ type: 'post', cache: false, url: '<?php 
        echo CATEGORY_MAPPING_URL_AJAX;
        ?>
', data: data, success: function(data){
						if (data=="ok") {
                          alert("ok");
                 	  	}
					}
				})
		  })

		  jQuery('.remove_from_all_sets').click(function() {
          	  	var e = $(this);
          	  	id_attribute = e.attr("id_attribute");
				var data = {  'supplier': supplier, 'id_attribute': id_attribute, 'to_do': "REMOVE_FROM_ALL_SETS" };
				$.ajax({ type: 'post', cache: false, url: '<?php 
        echo CATEGORY_MAPPING_URL_AJAX;
        ?>
', data: data, success: function(data){
						if (data=="ok") {
                          alert("ok");
                 	  	}
					}
				})
		  })
      //-->
      </script>

       <?php 
    }
Example #8
0
 public function run()
 {
     // Set tracking
     $track = $this->getArgs('t', 'track');
     if ($track !== false) {
         if (!strcmp('0', $track)) {
             $doTracking = $this->_helper->disable();
         } else {
             $doTracking = $this->_helper->enable();
         }
     } else {
         $doTracking = $this->_helper->isActive();
     }
     // Set username
     $user = $this->getArgs('u', 'user');
     if ($user !== false) {
         $this->_helper->setUser($user);
     }
     if ($this->getArgs('s', 'status')) {
         $this->_printHeader();
         $pendingList = $this->_io->getPendingList();
         if (count($pendingList)) {
             printf("Pending Actions list:\r\n");
             foreach ($pendingList as $i => $row) {
                 $actionDescr = sprintf("ID: %d\t - %s (%s on %s)", $i + 1, $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_ACTION_DESCR], $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_ACTION_USER], strftime("%c", $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_ACTION_TIMESTAMP]));
                 $spacer = str_repeat(" ", max(0, 40 - strlen($actionDescr)));
                 printf("%s\r\n", $actionDescr);
             }
             printf("\r\nTotal pending actions: %d\r\n", count($pendingList));
         } else {
             printf("There aren't any pending actions to execute.\r\n");
         }
     } else {
         if ($limit = $this->getArgs('hi', 'history')) {
             $this->_printHeader();
             $historyList = $this->_io->getHistoryList($limit);
             if (count($historyList)) {
                 printf("Global Actions list:\r\n");
                 foreach ($historyList as $i => $row) {
                     $actionDescr = sprintf("ID: %d\t - %s (%s on %s)", $i + 1, $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_ACTION_DESCR], $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_ACTION_USER], strftime("%c", $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_ACTION_TIMESTAMP]));
                     $spacer = str_repeat(" ", max(0, 40 - strlen($actionDescr)));
                     printf("%s\r\n", $actionDescr);
                 }
                 printf("\r\nTotal global actions listed: %d\r\n", count($historyList));
             } else {
                 printf("There aren't any actions tracked.\r\n");
             }
         } else {
             if ($id = $this->getArgs('r', 'run')) {
                 $this->_printHeader();
                 $pendingList = $this->_io->getPendingList();
                 if (count($pendingList)) {
                     $executed = 0;
                     $session = Mage::getSingleton('adminhtml/session');
                     foreach ($pendingList as $i => $row) {
                         if ($id > 0 && $i + 1 != $id) {
                             continue;
                         }
                         $actionExecutorClass = $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_EXECUTOR_CLASS];
                         $actionExecutorVersion = $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_VERSION];
                         $controllerModule = $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_CONTROLLER_MODULE];
                         $controllerName = $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_CONTROLLER_NAME];
                         $controllerClassName = $this->_getControllerClassName($controllerModule, $controllerName);
                         if (class_exists($actionExecutorClass)) {
                             $controllerFileName = $this->_getControllerClassPath($controllerModule, $controllerName);
                             if (file_exists($controllerFileName)) {
                                 include_once $controllerFileName;
                             } else {
                                 printf("Error: file '%s' not found!\r\n", $controllerFileName);
                             }
                             if (class_exists($controllerClassName)) {
                                 $actionExecutor = new $actionExecutorClass();
                                 $parameters = $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_ACTION_PARAMS];
                                 try {
                                     $request = $actionExecutor->decode($parameters, $actionExecutorVersion);
                                     $controller = new $controllerClassName($request, new PugMoRe_Mageploy_Controller_Response_Http());
                                     $action = $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_ACTION_NAME] . 'Action';
                                     $controller->preDispatch();
                                     $controller->{$action}();
                                     $controller->postDispatch();
                                 } catch (Zend_Controller_Response_Exception $e) {
                                     # do nothing: avoid "Headers already sent" error message
                                 } catch (Exception $e) {
                                     $session->addError($e->getMessage());
                                 }
                                 // Add messages in body response in case of Ajax requests
                                 $messages = $session->getMessages(true);
                                 if ($request && $request->getParam('isAjax', false)) {
                                     $body = $controller->getResponse()->getBody();
                                     $msg = Mage::getSingleton('core/message')->notice($body);
                                     $messages->add($msg);
                                 }
                                 foreach ($messages->getItems() as $message) {
                                     $messageType = $message->getType();
                                     switch ($messageType) {
                                         case Mage_Core_Model_Message::ERROR:
                                             $color = self::TERM_COLOR_RED;
                                             break;
                                         case Mage_Core_Model_Message::SUCCESS:
                                             $color = self::TERM_COLOR_GREEN;
                                             break;
                                         default:
                                             #break intentionally omitted
                                         #break intentionally omitted
                                         case Mage_Core_Model_Message::WARNING:
                                             #break intentionally omitted
                                         #break intentionally omitted
                                         case Mage_Core_Model_Message::NOTICE:
                                             $color = self::TERM_COLOR_YELLOW;
                                             break;
                                     }
                                     printf("Action ID #%d - %s %s\r\n", $i + 1, $this->__getColoredString($message->getType(), $color), $message->getText());
                                 }
                                 $executed++;
                                 // register executed action
                                 $this->_io->done($row);
                             } else {
                                 printf("Error: class '%s' not found!\r\n", $controllerClassName);
                             }
                         } else {
                             printf("Error: class '%s' not found!\r\n", $actionExecutorClass);
                         }
                         // Yes, PHP is Object Oriented but don't forget the
                         // Superglobals! After all PHP is not Java :-)
                         $_GET = array();
                         $_POST = array();
                         $_REQUEST = array();
                         // And don't forget to reinitialize Magento to avoid
                         // problems with already populated objects (i.e. registry)
                         Mage::reset();
                         Mage::init($this->_appCode, $this->_appType);
                     }
                     // end foreach
                     printf("\r\nExecuted actions: %d/%d\r\n", $executed, count($pendingList));
                 } else {
                     printf("There aren't any pending actions to execute.\r\n");
                 }
             } else {
                 echo $this->usageHelp($doTracking);
             }
         }
     }
     printf("\r\n");
 }
Example #9
0
 */
$mageShellFilename = 'Mageshell.php';
if (!file_exists($mageShellFilename)) {
    echo $mageShellFilename . 'was not found';
    exit;
}
require_once $mageShellFilename;
#Varien_Profiler::enable();
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(022);
/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
Mage::init($mageRunCode, $mageRunType);
/* Start session */
if (isset($options['u']) && isset($options['p'])) {
    $username = $options['u'];
    $password = $options['p'];
    $user = Mage::getSingleton('admin/session')->login($username, $password);
    if (!is_object($user) || !$user->getId()) {
        echo "Admin login failed.\n";
    } else {
        echo "Logged in as {$user->getUsername()}\n";
    }
} else {
    if (isset($options['a'])) {
        Mage::app()->setCurrentStore('admin');
        echo "Using admin context.\n";
    } else {
Example #10
0
function updateSeller($data)
{
    include '../app/Mage.php';
    Mage::init();
    if (isset($data['sku']) && $data['sku'] != '' && isset($data['status']) && $data['status'] != '' && isset($data['price']) && $data['price'] != '' && isset($data['special_price']) && isset($data['sellerCode']) && $data['sellerCode'] != '' && isset($data['inventory']) && $data['inventory'] != '') {
        if ($data['status'] == 1 || $data['status'] == 2) {
            if (is_numeric($data['price'])) {
                if (is_numeric($data['inventory'])) {
                    $sku = $data['sku'] . '-' . $data['sellerCode'];
                    $product = Mage::getModel('catalog/product');
                    $productId = $product->getIdBySku($sku);
                    if (isset($productId) && $productId != '') {
                        $product = $product->load($productId);
                        $product->setStatus($data['status']);
                        $product->setPrice($data['price']);
                        $product->setSpecialPrice($data['special_price']);
                        $product->save();
                        $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
                        if ($stockItem->getId() > 0 and $stockItem->getManageStock()) {
                            $qty = $data['inventory'];
                            $stockItem->setQty($qty);
                            $stockItem->setIsInStock((int) ($qty > 0));
                            $stockItem->save();
                        }
                        $proArr['data'] = null;
                        $proArr['message'] = "Update Success";
                    } else {
                        $proArr['data'] = null;
                        $proArr['message'] = "Sku doesnot exist";
                    }
                } else {
                    $proArr['data'] = null;
                    $proArr['message'] = "Inventory need be number";
                }
            } else {
                $proArr['data'] = null;
                $proArr['message'] = "price need be in correct format EX: 109.23";
            }
        } else {
            $proArr['data'] = null;
            $proArr['message'] = "status can be either 1 or 2";
        }
    } else {
        $proArr['data'] = null;
        $proArr['message'] = "Seller code, sku, Price, special_price, Inventory and status are required";
    }
    return $proArr;
}
function sendChangePasswordMail($data)
{
    include '../app/Mage.php';
    Mage::init();
    if (isset($data['user_id']) && trim($data['user_id']) != '' && isset($data['new_password']) && trim($data['new_password']) != '') {
        $customer = Mage::getModel('customer/customer')->load(trim($data['user_id']));
        if ($customer->getEmail()) {
            $templateId = 2;
            //template id for sending customer data
            $mailTemplate = Mage::getModel('core/email_template');
            $template_collection = $mailTemplate->load($templateId);
            $template_data = $template_collection->getData();
            $templateId = $template_data['template_id'];
            $mailSubject = $template_data['template_subject'];
            $from_email = Mage::getStoreConfig('trans_email/ident_sales/email');
            //fetch sender email
            $from_name = Mage::getStoreConfig('trans_email/ident_sales/name');
            //fetch sender name
            $sender = array('name' => 'msupply', 'email' => '*****@*****.**');
            $mailfirstname = $customer->getFirstname();
            $vars = array('newpassword' => trim($data['new_password']), 'firstname' => $mailfirstname);
            $email = $customer->getEmail();
            $storeId = Mage::app()->getStore()->getId();
            $model = $mailTemplate->setReplyTo($sender['email'])->setTemplateSubject($mailSubject);
            $model->sendTransactional($templateId, $sender, $email, 'msupply', $vars, $storeId);
            //sms
            $sms = new Celusion_SMSConneXion_Model_Observer();
            $observer = new Varien_Event_Observer();
            $observer->setData(array('customer' => $customer));
            $sms->sendUpdatePasswordAlertsApi($observer);
            $proArr['message'] = "sent";
            $proArr['status'] = 'ok';
        } else {
            $proArr['message'] = "user_id doesnot match";
            $proArr['status'] = 'failed';
        }
    } else {
        $proArr['message'] = "user_id and new_password is required";
        $proArr['status'] = 'failed';
    }
    return $proArr;
}
Example #12
0
 /**
  * Constructor
  */
 public function __construct()
 {
     Mage::init();
     $this->_getInstaller()->setDataModel($this->_getDataModel());
 }
define('MAGENTO_ROOT', getcwd());
//Initialize Magento
require_once MAGENTO_ROOT . '/app/Mage.php';
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
$website = 'base';
if (isset($_SERVER['SERVER_NAME'])) {
    switch ($_SERVER['SERVER_NAME']) {
        case 'website.address.com':
            $website = 'website_code';
            break;
    }
}
$mageRunType = 'website';
Mage::init($website, $mageRunType);
try {
    $code = 'media_gallery';
    $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $code);
    $table = Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media::GALLERY_TABLE;
    $connection = Mage::getSingleton('core/resource')->getConnection('default_read');
    $select = $connection->select()->from($attribute->getResource()->getTable($table), 'value')->where('attribute_id=?', $attribute->getId())->distinct();
    $images = $connection->fetchCol($select);
    unset($attribute);
    unset($connection);
    unset($select);
    Mage::log($website, null, 's3.log');
    $totalImages = count($images);
    Mage::log($totalImages . ' images to process', null, 's3.log');
    //Get settings for S3
    $accessKey = Mage::getStoreConfig(MVentory_CDN_Model_Config::ACCESS_KEY);
Example #14
0
$pathInfo = str_replace('..', '', ltrim($request->getPathInfo(), '/'));
$filePath = str_replace('/', DS, $publicDirectory . DS . $pathInfo);
if ($mediaDirectory) {
    if (0 !== stripos($pathInfo, $mediaDirectory . '/') || is_dir($filePath)) {
        sendNotFoundPage();
    }
    $relativeFilename = str_replace($mediaDirectory . '/', '', $pathInfo);
    checkResource($relativeFilename, $allowedResources);
    sendFile($filePath);
}
$appOptions = new Mage_Core_Model_App_Options($_SERVER);
if (empty($mediaDirectory)) {
    Mage::init($appOptions->getRunCode(), $appOptions->getRunType(), $appOptions->getRunOptions());
} else {
    $appRunOptions = array_merge($appOptions->getRunOptions(), array('cache' => array('disallow_save' => true)));
    Mage::init($appOptions->getRunCode(), $appOptions->getRunType(), $appRunOptions, array('Mage_Core'));
}
Mage::app()->requireInstalledInstance();
if (!$mediaDirectory) {
    $config = Mage_Core_Model_File_Storage::getScriptConfig();
    $mediaDirectory = str_replace($publicDirectory, '', $config['media_directory']);
    $allowedResources = array_merge($allowedResources, $config['allowed_resources']);
    $relativeFilename = str_replace($mediaDirectory . '/', '', $pathInfo);
    $fp = fopen($configCacheFile, 'w');
    if (flock($fp, LOCK_EX | LOCK_NB)) {
        ftruncate($fp, 0);
        fwrite($fp, json_encode($config));
    }
    flock($fp, LOCK_UN);
    fclose($fp);
    checkResource($relativeFilename, $allowedResources);
    sendFile($filePath);
}
$mageFilename = 'app/Mage.php';
if (!file_exists($mageFilename)) {
    echo $mageFilename . ' was not found';
}
require_once $mageFilename;
umask(0);
/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
if (empty($mediaDirectory)) {
    Mage::init($mageRunCode, $mageRunType);
} else {
    Mage::init($mageRunCode, $mageRunType, array(), array('Mage_Core'));
}
if (!$mediaDirectory) {
    $config = Mage_Core_Model_File_Storage::getScriptConfig();
    $mediaDirectory = str_replace($bp . $ds, '', $config['media_directory']);
    $allowedResources = array_merge($allowedResources, $config['allowed_resources']);
    $relativeFilename = str_replace($mediaDirectory . '/', '', $pathInfo);
    $fp = fopen($configCacheFile, 'w');
    if (flock($fp, LOCK_EX | LOCK_NB)) {
        ftruncate($fp, 0);
        fwrite($fp, json_encode($config));
    }
    flock($fp, LOCK_UN);
    fclose($fp);
    checkResource($relativeFilename, $allowedResources);
}
Example #16
0
File: api.php Project: Vedariy/test
    echo 'Mage file not found';
    exit;
}
require $mageFilename;
if (!Mage::isInstalled()) {
    echo 'Application is not installed yet, please complete install wizard first.';
    exit;
}
if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
    Mage::setIsDeveloperMode(true);
}
#ini_set('display_errors', 1);
// emulate index.php entry point for correct URLs generation in API
Mage::register('custom_entry_point', true);
Mage::$headersSentThrowsException = false;
Mage::init('admin');
Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);
Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_ADMINHTML, Mage_Core_Model_App_Area::PART_EVENTS);
// query parameter "type" is set by .htaccess rewrite rule
$apiAlias = Mage::app()->getRequest()->getParam('type');
// check request could be processed by API2
if (in_array($apiAlias, Mage_Api2_Model_Server::getApiTypes())) {
    /** @var $server Mage_Api2_Model_Server */
    $server = Mage::getSingleton('api2/server');
    $server->run();
} else {
    /* @var $server Mage_Api_Model_Server */
    $server = Mage::getSingleton('api/server');
    $adapterCode = $server->getAdapterCodeByAlias($apiAlias);
    // if no adapters found in aliases - find it by default, by code
    if (null === $adapterCode) {
Example #17
0
if ($mediaDirectory) {
    if (0 !== stripos($pathInfo, $mediaDirectory . '/') || is_dir($filePath)) {
        sendNotFoundPage();
    }
    $relativeFilename = str_replace($mediaDirectory . '/', '', $pathInfo);
    checkResource($relativeFilename, $allowedResources);
    sendFile($filePath);
}
/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
if (empty($mediaDirectory)) {
    Mage::init($mageRunCode, $mageRunType);
} else {
    Mage::init($mageRunCode, $mageRunType, array('cache' => array('disallow_save' => true)), array('Mage_Core'));
}
if (!$mediaDirectory) {
    $config = Mage_Core_Model_File_Storage::getScriptConfig();
    $mediaDirectory = str_replace($publicDirectory, '', $config['media_directory']);
    $allowedResources = array_merge($allowedResources, $config['allowed_resources']);
    $relativeFilename = str_replace($mediaDirectory . '/', '', $pathInfo);
    $fp = fopen($configCacheFile, 'w');
    if (flock($fp, LOCK_EX | LOCK_NB)) {
        ftruncate($fp, 0);
        fwrite($fp, json_encode($config));
    }
    flock($fp, LOCK_UN);
    fclose($fp);
    checkResource($relativeFilename, $allowedResources);
}
Example #18
0
 public function __construct()
 {
     \Mage::init();
 }