Fataler Fehler: Rufen Sie auf undefined Method mage_checkout_quotecontroller :: _ getSession () in Magento

magento.stackexchange https://magento.stackexchange.com/questions/13768

Frage

Ich bin neu in Magento und meine Absicht ist es, eine Anfrage nach Zitat zu erstellen wie dieser Link.So dafür habe ich das benutzerdefinierte Modul erstellt, um das Angebot anzufordern. Darin habe ich die Angebotsschaltflächen hinzufügen \app\design\frontend\mypackage\default\template\catalog\product\list.phtml

<button type="button" title="<?php echo $this->__('Add to Quote') ?>" class="button btn-cart" onclick="setLocation('<?php echo Mage::getUrl('checkout/quote/index'); ?>')"><span><span><?php echo $this->__('Add to Quote') ?></span></span></button>

Wenn der Kunde auf die Schaltfläche zur Angebot klicken, habe ich umgeleitet/navigiert, um die Zitatseite zu erhalten. Dafür habe ich QuotingController in erstellt magento\app\code\core\Mage\Checkout\controllers\QuoteController.php

<?php

class Mage_Checkout_QuoteController extends Mage_Core_Controller_Front_Action
{

    protected function _getCart()
    {
        return Mage::getSingleton('checkout/cart');
    }

    /**
     * Get current active quote instance
     *
     * @return Mage_Sales_Model_Quote
     */
    protected function _getQuote()
    {
        return $this->_getCart()->getQuote();
    }

    function indexAction()
    {

      /*  $this->loadLayout();
        $this->_initLayoutMessages('customer/session');
        $this->getLayout()->getBlock('head')->setTitle($this->__('Request for Quote'));
        $this->renderLayout();
        Mage::log("Request for quote");*/

      $cart = $this->_getCart();
        if ($cart->getQuote()->getItemsCount()) {
            $cart->init();
            $cart->save();

            if (!$this->_getQuote()->validateMinimumAmount()) {
                $minimumAmount = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())
                    ->toCurrency(Mage::getStoreConfig('sales/minimum_order/amount'));

                $warning = Mage::getStoreConfig('sales/minimum_order/description')
                    ? Mage::getStoreConfig('sales/minimum_order/description')
                    : Mage::helper('checkout')->__('Minimum order amount is %s', $minimumAmount);

                $cart->getCheckoutSession()->addNotice($warning);
            }
        }

        // Compose array of messages to add
        $messages = array();
        foreach ($cart->getQuote()->getMessages() as $message) {
            if ($message) {
                // Escape HTML entities in quote message to prevent XSS
                $message->setCode(Mage::helper('core')->escapeHtml($message->getCode()));
                $messages[] = $message;
            }
        }
        $cart->getCheckoutSession()->addUniqueMessages($messages);

        /**
         * if customer enteres shopping cart we should mark quote
         * as modified bc he can has checkout page in another window.
         */
        $this->_getSession()->setCartWasUpdated(true);

        Varien_Profiler::start(__METHOD__ . 'cart_display');
        $this
            ->loadLayout()
            ->_initLayoutMessages('checkout/session')
            ->_initLayoutMessages('catalog/session')
            ->getLayout()->getBlock('head')->setTitle($this->__('Request for Quote'));
        $this->renderLayout();
        Varien_Profiler::stop(__METHOD__ . 'cart_display');
    }



    public function sendemailAction()
    {
        //Fetch submited params      

        $params = $this->getRequest()->getParams();
        $mail = new Zend_Mail();
        $to = $params['email'];

        Mage::log((array)$to);

        $sub = 'Test Email From Magento SMTP Pro Module';
        $body = $params['comment'];
        Mage::log((array)$body);

        $mail->addTo($to)
            ->setFrom("dotnet@gmail.com")
            ->setSubject($sub)
            ->setBodyText($body);

        $websiteModel = Mage::app()->getWebsite($this->getRequest()->getParam('website'));

        try {
            $transport = Mage::helper('smtppro')->getTransport($websiteModel->getId());

            Mage::log((array)$transport);

            $mail->send($transport);

            Mage::dispatchEvent('smtppro_email_after_send',
                array('to' => $to,
                    'template' => "SMTPPro Self Test",
                    'subject' => $sub,
                    'html' => false,
                    'email_body' => $body));

            $msg =  "<br/> Test email was sent successfully.";
            Mage::log("Test email was sent successfully");


        } catch (Exception $e) {
            $success = false;
            $msg = $msg . "<br/> Unable to send test email. Exception message was: " . $e->getMessage() . "...";
            $msg = $msg . "<br/> Please check and double check your username and password.";
            Mage::log("Test email was not sent successfully: " . $e->getMessage());
        }

        $this->_redirect("*/quote/index");

    }
}

Und app\design\frontend\mypackage\default\layout\checkout.xml Datei Ich habe die meine benutzerdefinierte Datei registriert, die ist test.phtml Datei

<checkout_quote_index translate="label">
        <label>Request for quote</label>
        <remove name="right"/>
        <remove name="left"/>
        <!-- Mage_Checkout -->
        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>
        </reference>
        <reference name="content">
            <block template="checkout/cart/test.phtml" name="quote" type="checkout/cart_quote"></block>
        </reference>

    </checkout_quote_index>

Und schließlich habe ich die Anforderung für die Zitat -Titelseite als angezeigt test.phtml

magento\app\design\frontend\mypackage\default\template\checkout\cart\test.phtml in this I have wrote below code

<div class="cart">
    <div class="page-title title-buttons">
        <h1><?php echo $this->__('Shopping Cart') ?></h1>
        <?php if(!$this->hasError()): ?>
            <ul class="checkout-types">
                <?php foreach ($this->getMethods('top_methods') as $method): ?>
                    <?php if ($methodHtml = $this->getMethodHtml($method)): ?>
                        <li><?php echo $methodHtml; ?></li>
                    <?php endif; ?>
                <?php endforeach; ?>
            </ul>
        <?php endif; ?>
    </div>
    <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
    <?php echo $this->getChildHtml('form_before') ?>
    <form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">
        <fieldset>
            <table id="shopping-cart-table" class="data-table cart-table">
                <col width="1" />
                <col />
                <col width="1" />
                <?php if ($this->helper('wishlist')->isAllowInCart()) : ?>
                    <col width="1" />
                <?php endif ?>
                <?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
                    <col width="1" />
                <?php endif; ?>
                <?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
                    <col width="1" />
                <?php endif; ?>
                <col width="1" />
                <?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
                    <col width="1" />
                <?php endif; ?>
                <?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
                    <col width="1" />
                <?php endif; ?>
                <col width="1" />

                <?php $mergedCells = ($this->helper('tax')->displayCartBothPrices() ? 2 : 1); ?>
                <thead>
                <tr>
                    <th rowspan="<?php echo $mergedCells; ?>">&nbsp;</th>
                    <th rowspan="<?php echo $mergedCells; ?>"><span class="nobr"><?php echo $this->__('Product Name') ?></span></th>
                    <th rowspan="<?php echo $mergedCells; ?>"></th>
                    <?php if ($this->helper('wishlist')->isAllowInCart()) : ?>
                        <th rowspan="<?php echo $mergedCells; ?>" class="a-center"><span class="nobr"><?php echo $this->__('Move to Wishlist') ?></span></th>
                    <?php endif ?>
                    <th class="a-center" colspan="<?php echo $mergedCells; ?>"><span class="nobr"><?php echo $this->__('Unit Price') ?></span></th>
                    <th rowspan="<?php echo $mergedCells; ?>" class="a-center"><?php echo $this->__('Qty') ?></th>
                    <th class="a-center" colspan="<?php echo $mergedCells; ?>"><?php echo $this->__('Subtotal') ?></th>
                    <th rowspan="<?php echo $mergedCells; ?>" class="a-center">&nbsp;</th>
                </tr>
                <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                    <tr>
                        <th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
                        <th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
                        <th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
                        <th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
                    </tr>
                <?php endif; ?>
                </thead>
                <tfoot>
                <tr>
                    <td colspan="50" class="a-right">
                        <?php if($this->getContinueShoppingUrl()): ?>
                            <button type="button" title="<?php echo $this->__('Continue Shopping') ?>" class="button btn-continue" onclick="setLocation('<?php echo $this->getContinueShoppingUrl() ?>')"><span><span><?php echo $this->__('Continue Shopping') ?></span></span></button>
                        <?php endif; ?>
                        <button type="submit" name="update_cart_action" value="update_qty" title="<?php echo $this->__('Update Shopping Cart'); ?>" class="button btn-update"><span><span><?php echo $this->__('Update Shopping Cart'); ?></span></span></button>
                        <button type="submit" name="update_cart_action" value="empty_cart" title="<?php echo $this->__('Clear Shopping Cart'); ?>" class="button btn-empty" id="empty_cart_button"><span><span><?php echo $this->__('Clear Shopping Cart'); ?></span></span></button>
                        <!--[if lt IE 8]>
                        <input type="hidden" id="update_cart_action_container" />
                        <script type="text/javascript">
                            //<![CDATA[
                                Event.observe(window, 'load', function()
                                {
                                    // Internet Explorer (lt 8) does not support value attribute in button elements
                                    $emptyCartButton = $('empty_cart_button');
                                    $cartActionContainer = $('update_cart_action_container');
                                    if ($emptyCartButton && $cartActionContainer) {
                                        Event.observe($emptyCartButton, 'click', function()
                                        {
                                            $emptyCartButton.setAttribute('name', 'update_cart_action_temp');
                                            $cartActionContainer.setAttribute('name', 'update_cart_action');
                                            $cartActionContainer.setValue('empty_cart');
                                        });
                                    }

                                });
                            //]]>
                            </script>
                            <![endif]-->
                    </td>
                </tr>
                </tfoot>
                <tbody>
                <?php foreach($this->getItems() as $_item): ?>
                    <?php echo $this->getItemHtml($_item) ?>
                <?php endforeach ?>
                </tbody>
            </table>
            <script type="text/javascript">decorateTable('shopping-cart-table')</script>
        </fieldset>
    </form>
    <div class="cart-collaterals">
        <div class="col2-set">
            <div class="col-1">
                <?php echo $this->getChildHtml('crosssell') ?>
            </div>
            <div class="col-2">
                <?php /* Extensions placeholder */ ?>
                <?php echo $this->getChildHtml('checkout.cart.extra') ?>
                <?php echo $this->getChildHtml('coupon') ?>
                <?php if (!$this->getIsVirtual()): echo $this->getChildHtml('shipping'); endif; ?>
            </div>
        </div>
        <div class="totals">
            <?php echo $this->getChildHtml('totals'); ?>
            <?php if(!$this->hasError()): ?>
                <ul class="checkout-types">
                    <?php foreach ($this->getMethods('methods') as $method): ?>
                        <?php if ($methodHtml = $this->getMethodHtml($method)): ?>
                            <li><?php echo $methodHtml; ?></li>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </ul>
            <?php endif; ?>
        </div>
    </div>
</div>

Schließlich wird die Seite angezeigt, aber dies wird ein Fehler angezeigt Fatal error: Call to undefined method Mage_Checkout_QuoteController::_getSession()

Kann mir sagen, wo ich falsch gelaufen bin oder wie ich diese Funktionalität implementieren soll?

War es hilfreich?

Lösung

Der Fehler ist selbsterklärend. Sie rufen eine Methode an, die nicht existiert.

$this->_getSession()->setCartWasUpdated(true);

Definieren Sie entweder die Methode _getSession Oder entfernen Sie die oben erwähnte Linie, wenn Sie sie nicht benötigen.
Kleines Tipp aus dem Thema: Fügen Sie den Klassen nicht zum Klassen hinzu core Codepool und benutze die nicht Mage Namespace. Erstellen Sie Ihr eigenes Modul unter einem anderen Namespace in community oder local.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top