Exemplo n.º 1
0
 public function testToHtml()
 {
     $fieldSet = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Fieldset', [], [], '', false);
     $form = $this->getMock('Magento\\Framework\\Data\\Form', [], [], '', false);
     $attributeModel = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false);
     $entityType = $this->getMock('Magento\\Eav\\Model\\Entity\\Type', [], [], '', false);
     $formElement = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Text', ['setDisabled'], [], '', false);
     $directoryReadInterface = $this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface');
     $this->registry->expects($this->any())->method('registry')->with('entity_attribute')->willReturn($attributeModel);
     $this->formFactory->expects($this->any())->method('create')->willReturn($form);
     $form->expects($this->any())->method('addFieldset')->willReturn($fieldSet);
     $form->expects($this->any())->method('getElement')->willReturn($formElement);
     $fieldSet->expects($this->any())->method('addField')->willReturnSelf();
     $attributeModel->expects($this->any())->method('getDefaultValue')->willReturn('default_value');
     $attributeModel->expects($this->any())->method('setDisabled')->willReturnSelf();
     $attributeModel->expects($this->any())->method('getId')->willReturn(1);
     $attributeModel->expects($this->any())->method('getEntityType')->willReturn($entityType);
     $attributeModel->expects($this->any())->method('getIsUserDefined')->willReturn(false);
     $attributeModel->expects($this->any())->method('getAttributeCode')->willReturn('attribute_code');
     $this->localeDate->expects($this->any())->method('getDateFormat')->willReturn('mm/dd/yy');
     $entityType->expects($this->any())->method('getEntityTypeCode')->willReturn('entity_type_code');
     $this->eavData->expects($this->any())->method('getFrontendClasses')->willReturn([]);
     $formElement->expects($this->exactly(3))->method('setDisabled')->willReturnSelf();
     $this->yesNo->expects($this->any())->method('toOptionArray')->willReturn(['yes', 'no']);
     $this->filesystem->expects($this->any())->method('getDirectoryRead')->willReturn($directoryReadInterface);
     $directoryReadInterface->expects($this->any())->method('getRelativePath')->willReturn('relative_path');
     $this->block->setData(['action' => 'save']);
     $this->block->toHtml();
 }
 /**
  * @return array
  */
 public function toOptionArray()
 {
     $fields = [];
     $fields[] = ['value' => '0', 'label' => '-- Please Select --'];
     $apiEnabled = $this->helper->isEnabled($this->helper->getWebsite());
     if ($apiEnabled) {
         $savedCampaigns = $this->registry->registry('campaigns');
         if (is_array($savedCampaigns)) {
             $campaigns = $savedCampaigns;
         } else {
             //grab the datafields request and save to register
             $client = $this->helper->getWebsiteApiClient();
             $campaigns = $client->getCampaigns();
             $this->registry->register('campaigns', $campaigns);
         }
         //set the api error message for the first option
         if (isset($campaigns->message)) {
             //message
             $fields[] = ['value' => 0, 'label' => $campaigns->message];
         } elseif (!empty($campaigns)) {
             //loop for all campaing options
             foreach ($campaigns as $campaign) {
                 if (isset($campaign->name)) {
                     //@codingStandardsIgnoreStart
                     $fields[] = ['value' => $campaign->id, 'label' => addslashes($campaign->name)];
                     //@codingStandardsIgnoreEnd
                 }
             }
         }
     }
     return $fields;
 }
Exemplo n.º 3
0
 /**
  * Print Invoice Action
  *
  * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page
  */
 public function execute()
 {
     $invoiceId = (int) $this->getRequest()->getParam('invoice_id');
     if ($invoiceId) {
         $invoice = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Invoice')->load($invoiceId);
         $order = $invoice->getOrder();
     } else {
         $orderId = (int) $this->getRequest()->getParam('order_id');
         $order = $this->_objectManager->create('Magento\\Sales\\Model\\Order')->load($orderId);
     }
     if ($this->orderAuthorization->canView($order)) {
         $this->_coreRegistry->register('current_order', $order);
         if (isset($invoice)) {
             $this->_coreRegistry->register('current_invoice', $invoice);
         }
         /** @var \Magento\Framework\View\Result\Page $resultPage */
         $resultPage = $this->resultPageFactory->create();
         $resultPage->addHandle('print');
         return $resultPage;
     } else {
         /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         if ($this->_objectManager->get('Magento\\Customer\\Model\\Session')->isLoggedIn()) {
             $resultRedirect->setPath('*/*/history');
         } else {
             $resultRedirect->setPath('sales/guest/form');
         }
         return $resultRedirect;
     }
 }
Exemplo n.º 4
0
 /**
  * @return \Magento\Framework\Controller\ResultInterface
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function execute()
 {
     $id = $this->getRequest()->getParam('id');
     $model = $this->_objectManager->create('Magento\\Search\\Model\\Query');
     if ($id) {
         $model->load($id);
         if (!$model->getId()) {
             $this->messageManager->addError(__('This search no longer exists.'));
             /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
             $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
             $resultRedirect->setPath('search/*');
             return $resultRedirect;
         }
     }
     // set entered data if was error when we do save
     $data = $this->_objectManager->get('Magento\\Backend\\Model\\Session')->getPageData(true);
     if (!empty($data)) {
         $model->addData($data);
     }
     $this->coreRegistry->register('current_catalog_search', $model);
     $resultPage = $this->createPage();
     $resultPage->getConfig()->getTitle()->prepend(__('Search Terms'));
     $resultPage->getConfig()->getTitle()->prepend($id ? $model->getQueryText() : __('New Search'));
     $resultPage->getLayout()->getBlock('adminhtml.search.term.edit')->setData('action', $this->getUrl('search/term/save'));
     $resultPage->addBreadcrumb($id ? __('Edit Search') : __('New Search'), $id ? __('Edit Search') : __('New Search'));
     return $resultPage;
 }
Exemplo n.º 5
0
 /**
  * Print Invoice Action
  *
  * @return void
  */
 public function execute()
 {
     $invoiceId = (int) $this->getRequest()->getParam('invoice_id');
     if ($invoiceId) {
         $invoice = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Invoice')->load($invoiceId);
         $order = $invoice->getOrder();
     } else {
         $orderId = (int) $this->getRequest()->getParam('order_id');
         $order = $this->_objectManager->create('Magento\\Sales\\Model\\Order')->load($orderId);
     }
     if ($this->orderAuthorization->canView($order)) {
         $this->_coreRegistry->register('current_order', $order);
         if (isset($invoice)) {
             $this->_coreRegistry->register('current_invoice', $invoice);
         }
         $this->_view->loadLayout('print');
         $this->_view->renderLayout();
     } else {
         if ($this->_objectManager->get('Magento\\Customer\\Model\\Session')->isLoggedIn()) {
             $this->_redirect('*/*/history');
         } else {
             $this->_redirect('sales/guest/form');
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Get log model
  *
  * @return \ClassyLlama\AvaTax\Model\Log
  */
 public function getLog()
 {
     if (null === $this->currentLog) {
         $this->currentLog = $this->coreRegistry->registry('current_log');
     }
     return $this->currentLog;
 }
Exemplo n.º 7
0
 /**
  * @return void
  */
 public function execute()
 {
     $ipId = $this->getRequest()->getParam('id');
     /** @var \Rapidmage\Firewall\Model\Ip $model */
     $model = $this->_ipFactory->create();
     if ($ipId) {
         $model->load($ipId);
         if (!$model->getId()) {
             $this->messageManager->addError(__('This Ip no longer exists.'));
             $this->_redirect('*/*/');
             return;
         }
     }
     // Restore previously entered form data from session
     $data = $this->_session->getIpData(true);
     if (!empty($data)) {
         $model->setData($data);
     }
     $this->_coreRegistry->register('firewall_blackip', $model);
     /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
     $resultPage = $this->_resultPageFactory->create();
     $resultPage->setActiveMenu('Rapidmage_Firewall::main_menu');
     $resultPage->getConfig()->getTitle()->prepend(__('Firewall'));
     return $resultPage;
 }
Exemplo n.º 8
0
 public function execute()
 {
     // 1. Get ID and create model
     $id = $this->getRequest()->getParam("cat_id");
     $model = $this->_objectManager->create("OsmanSorkar\\Blog\\Model\\Category");
     if ($id) {
         $model->load($id);
         if (!$model->getId()) {
             $this->messageManager->addError(__("This Category no longer exists"));
             /** \Magento\Backend\Model\View\Result\Redirct $resultRedirct */
             $resultRedirect = $this->resultRedirectFactory->create();
             return $resultRedirect->setPath('*/*/');
         }
     }
     // 3. Set entered data if was error when we do save
     $data = $this->_objectManager->get('Magento\\Backend\\Model\\Session')->getFormData(true);
     if (!empty($data)) {
         $model->setData($data);
     }
     // 4. Register model to use later in blocks
     $this->_coreRegistry->register('blog_category', $model);
     // 5. Build edit form
     /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
     $resultPage = $this->resultPageFactory->create();
     $resultPage->setActiveMenu('Ashsmith_Blog::category');
     $resultPage->addBreadcrumb(__('Blog Category Edit'), __('Blog Category Edit'));
     $resultPage->addBreadcrumb(__('Manage Blog Category'), __('Manage Blog Category'));
     $resultPage->getConfig()->getTitle()->prepend(__('Blog Category Edit'));
     return $resultPage;
 }
Exemplo n.º 9
0
    /**
     * Action for reorder
     *
     * @return \Magento\Framework\Controller\ResultInterface
     */
    public function executeInternal()
    {
        $result = $this->orderLoader->load($this->_request);
        if ($result instanceof \Magento\Framework\Controller\ResultInterface) {
            return $result;
        }
        $order = $this->_coreRegistry->registry('current_order');
        /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
        $resultRedirect = $this->resultRedirectFactory->create();

        /* @var $cart \Magento\Checkout\Model\Cart */
        $cart = $this->_objectManager->get('Magento\Checkout\Model\Cart');
        $items = $order->getItemsCollection();
        foreach ($items as $item) {
            try {
                $cart->addOrderItem($item);
            } catch (\Magento\Framework\Exception\LocalizedException $e) {
                if ($this->_objectManager->get('Magento\Checkout\Model\Session')->getUseNotice(true)) {
                    $this->messageManager->addNotice($e->getMessage());
                } else {
                    $this->messageManager->addError($e->getMessage());
                }
                return $resultRedirect->setPath('*/*/history');
            } catch (\Exception $e) {
                $this->messageManager->addException($e, __('We can\'t add this item to your shopping cart right now.'));
                return $resultRedirect->setPath('checkout/cart');
            }
        }

        $cart->save();
        return $resultRedirect->setPath('checkout/cart');
    }
Exemplo n.º 10
0
 /**
  * @return \Magento\Framework\Controller\Result\Forward|\Magento\Framework\View\Result\Page
  */
 public function execute()
 {
     $articleId = (int) $this->getRequest()->getParam('id');
     $article = $this->articleFactory->create();
     $article->load($articleId);
     if (!$article->isActive()) {
         $resultForward = $this->resultForwardFactory->create();
         $resultForward->forward('noroute');
         return $resultForward;
     }
     $this->coreRegistry->register('current_article', $article);
     $resultPage = $this->resultPageFactory->create();
     $title = $article->getMetaTitle() ?: $article->getName();
     $resultPage->getConfig()->getTitle()->set($title);
     $resultPage->getConfig()->setDescription($article->getMetaDescription());
     $resultPage->getConfig()->setKeywords($article->getMetaKeywords());
     if ($this->scopeConfig->isSetFlag(self::BREADCRUMBS_CONFIG_PATH, ScopeInterface::SCOPE_STORE)) {
         /** @var \Magento\Theme\Block\Html\Breadcrumbs $breadcrumbsBlock */
         $breadcrumbsBlock = $resultPage->getLayout()->getBlock('breadcrumbs');
         if ($breadcrumbsBlock) {
             $breadcrumbsBlock->addCrumb('home', ['label' => __('Home'), 'link' => $this->_url->getUrl('')]);
             $breadcrumbsBlock->addCrumb('articles', ['label' => __('Articles'), 'link' => $this->urlModel->getListUrl()]);
             $breadcrumbsBlock->addCrumb('article-' . $article->getId(), ['label' => $article->getName()]);
         }
     }
     return $resultPage;
 }
Exemplo n.º 11
0
 /**
  * Execute before toHtml() code.
  *
  * @return $this
  */
 public function _beforeToHtml()
 {
     $this->_currency = $this->_currencyFactory->create()->load($this->_scopeConfig->getValue(Currency::XML_PATH_CURRENCY_BASE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
     $this->_collection = $this->_collectionFactory->create()->setCustomerIdFilter((int) $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID))->setOrderStateFilter(Order::STATE_CANCELED, true)->load();
     $this->_groupedCollection = [];
     foreach ($this->_collection as $sale) {
         if ($sale->getStoreId() !== null) {
             $store = $this->_storeManager->getStore($sale->getStoreId());
             $websiteId = $store->getWebsiteId();
             $groupId = $store->getGroupId();
             $storeId = $store->getId();
             $sale->setWebsiteId($store->getWebsiteId());
             $sale->setWebsiteName($store->getWebsite()->getName());
             $sale->setGroupId($store->getGroupId());
             $sale->setGroupName($store->getGroup()->getName());
         } else {
             $websiteId = 0;
             $groupId = 0;
             $storeId = 0;
             $sale->setStoreName(__('Deleted Stores'));
         }
         $this->_groupedCollection[$websiteId][$groupId][$storeId] = $sale;
         $this->_websiteCounts[$websiteId] = isset($this->_websiteCounts[$websiteId]) ? $this->_websiteCounts[$websiteId] + 1 : 1;
     }
     return parent::_beforeToHtml();
 }
Exemplo n.º 12
0
 /**
  * Retrieve text for header element depending on loaded page
  *
  * @return string
  */
 public function getHeaderText()
 {
     $process = $this->_coreRegistry->registry('current_index_process');
     if ($process && $process->getId()) {
         return __("'%1' Index Process Information", $process->getIndexer()->getName());
     }
 }
Exemplo n.º 13
0
 /**
  * Forms script response
  *
  * @return string
  */
 public function _toHtml()
 {
     $updateResult = $this->_coreRegistry->registry('composite_update_result');
     $resultJson = $this->_jsonEncoder->encode($updateResult);
     $jsVarname = $updateResult->getJsVarName();
     return $this->_jsHelper->getScript(sprintf('var %s = %s', $jsVarname, $resultJson));
 }
 /**
  * Apply catalog price rules to product in admin
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $product = $observer->getEvent()->getProduct();
     $storeId = $product->getStoreId();
     $date = $this->localeDate->scopeDate($storeId);
     $key = false;
     $ruleData = $this->coreRegistry->registry('rule_data');
     if ($ruleData) {
         $wId = $ruleData->getWebsiteId();
         $gId = $ruleData->getCustomerGroupId();
         $pId = $product->getId();
         $key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}";
     } elseif ($product->getWebsiteId() !== null && $product->getCustomerGroupId() !== null) {
         $wId = $product->getWebsiteId();
         $gId = $product->getCustomerGroupId();
         $pId = $product->getId();
         $key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}";
     }
     if ($key) {
         if (!$this->rulePricesStorage->hasRulePrice($key)) {
             $rulePrice = $this->resourceRuleFactory->create()->getRulePrice($date, $wId, $gId, $pId);
             $this->rulePricesStorage->setRulePrice($key, $rulePrice);
         }
         if ($this->rulePricesStorage->getRulePrice($key) !== false) {
             $finalPrice = min($product->getData('final_price'), $this->rulePricesStorage->getRulePrice($key));
             $product->setFinalPrice($finalPrice);
         }
     }
     return $this;
 }
Exemplo n.º 15
0
 /**
  * Get current product instance
  *
  * @return \Magento\Catalog\Model\Product
  */
 public function getProduct()
 {
     if (!is_null($this->_product)) {
         return $this->_product;
     }
     return $this->_coreRegistry->registry('product');
 }
Exemplo n.º 16
0
 /**
  * Get associated grouped products grid popup
  *
  * @return \Magento\Framework\View\Result\Layout
  */
 public function execute()
 {
     $productId = (int) $this->getRequest()->getParam('id');
     /** @var $product \Magento\Catalog\Model\Product */
     $product = $this->factory->create();
     $product->setStoreId($this->getRequest()->getParam('store', 0));
     $typeId = $this->getRequest()->getParam('type');
     if (!$productId && $typeId) {
         $product->setTypeId($typeId);
     }
     $product->setData('_edit_mode', true);
     if ($productId) {
         try {
             $product->load($productId);
         } catch (\Exception $e) {
             $product->setTypeId(\Magento\Catalog\Model\Product\Type::DEFAULT_TYPE);
             $this->logger->critical($e);
         }
     }
     $setId = (int) $this->getRequest()->getParam('set');
     if ($setId) {
         $product->setAttributeSetId($setId);
     }
     $this->registry->register('current_product', $product);
     /** @var \Magento\Framework\View\Result\Layout $resultLayout */
     $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
     return $resultLayout;
 }
 /**
  * Save order into registry to use it in the overloaded controller.
  *
  * @param EventObserver $observer
  * @return $this
  */
 public function execute(EventObserver $observer)
 {
     /* @var $order \Magento\Sales\Model\Order */
     $order = $observer->getEvent()->getData('order');
     $this->_coreRegistry->register('hss_order', $order, true);
     return $this;
 }
Exemplo n.º 18
0
 /**
  * @return string
  */
 protected function _toHtml()
 {
     /** @var $rssObj \Magento\Rss\Model\Rss */
     $rssObj = $this->_rssFactory->create();
     $order = $this->_coreRegistry->registry('current_order');
     if (!$order) {
         return '';
     }
     $title = __('Order # %1 Notification(s)', $order->getIncrementId());
     $newUrl = $this->_urlBuilder->getUrl('sales/order/view', array('order_id' => $order->getId()));
     $rssObj->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'));
     /** @var $resourceModel \Magento\Rss\Model\Resource\Order */
     $resourceModel = $this->_orderFactory->create();
     $results = $resourceModel->getAllCommentCollection($order->getId());
     if ($results) {
         foreach ($results as $result) {
             $urlAppend = 'view';
             $type = $result['entity_type_code'];
             if ($type && $type != 'order') {
                 $urlAppend = $type;
             }
             $type = __(ucwords($type));
             $title = __('Details for %1 #%2', $type, $result['increment_id']);
             $description = '<p>' . __('Notified Date: %1<br/>', $this->formatDate($result['created_at'])) . __('Comment: %1<br/>', $result['comment']) . '</p>';
             $url = $this->_urlBuilder->getUrl('sales/order/' . $urlAppend, array('order_id' => $order->getId()));
             $rssObj->_addEntry(array('title' => $title, 'link' => $url, 'description' => $description));
         }
     }
     $title = __('Order #%1 created at %2', $order->getIncrementId(), $this->formatDate($order->getCreatedAt()));
     $url = $this->_urlBuilder->getUrl('sales/order/view', array('order_id' => $order->getId()));
     $description = '<p>' . __('Current Status: %1<br/>', $order->getStatusLabel()) . __('Total: %1<br/>', $order->formatPrice($order->getGrandTotal())) . '</p>';
     $rssObj->_addEntry(array('title' => $title, 'link' => $url, 'description' => $description));
     return $rssObj->createRssXml();
 }
Exemplo n.º 19
0
 /**
  * Edit sitemap
  *
  * @return void
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function execute()
 {
     // 1. Get ID and create model
     $id = $this->getRequest()->getParam('sitemap_id');
     $model = $this->_objectManager->create('Magento\\Sitemap\\Model\\Sitemap');
     // 2. Initial checking
     if ($id) {
         $model->load($id);
         if (!$model->getId()) {
             $this->messageManager->addError(__('This sitemap no longer exists.'));
             $this->_redirect('adminhtml/*/');
             return;
         }
     }
     // 3. Set entered data if was error when we do save
     $data = $this->_objectManager->get('Magento\\Backend\\Model\\Session')->getFormData(true);
     if (!empty($data)) {
         $model->setData($data);
     }
     // 4. Register model to use later in blocks
     $this->_coreRegistry->register('sitemap_sitemap', $model);
     // 5. Build edit form
     $this->_initAction()->_addBreadcrumb($id ? __('Edit Sitemap') : __('New Sitemap'), $id ? __('Edit Sitemap') : __('New Sitemap'))->_addContent($this->_view->getLayout()->createBlock('Magento\\Sitemap\\Block\\Adminhtml\\Edit'));
     $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Site Map'));
     $this->_view->getPage()->getConfig()->getTitle()->prepend($model->getId() ? $model->getSitemapFilename() : __('New Site Map'));
     $this->_view->renderLayout();
 }
 /**
  * Test for addFieldsToResponse method
  *
  * @return void
  */
 public function testAddFieldsToResponseSuccess()
 {
     $testData = $this->getAddFieldsToResponseSuccessTestData();
     $observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $orderPaymentMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Payment')->disableOriginalConstructor()->getMock();
     $instanceMock = $this->getMockBuilder('Magento\\Authorizenet\\Model\\Directpost')->disableOriginalConstructor()->getMock();
     $requestToAuthorizenetMock = $this->getMockBuilder('Magento\\Authorizenet\\Model\\Directpost\\Request')->disableOriginalConstructor()->setMethods(['setControllerActionName', 'setIsSecure', 'getData'])->getMock();
     $requestMock = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods(['getControllerName'])->getMockForAbstractClass();
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $this->coreRegistryMock->expects($this->once())->method('registry')->with('directpost_order')->willReturn($orderMock);
     $orderMock->expects($this->once())->method('getId')->willReturn($testData['order.getId']);
     $orderMock->expects($this->once())->method('getPayment')->willReturn($orderPaymentMock);
     $orderPaymentMock->expects($this->once())->method('getMethod')->willReturn($testData['orderPayment.getMethod']);
     $this->paymentMock->expects($this->exactly(2))->method('getCode')->willReturn($testData['payment.getCode']);
     $observerMock->expects($this->atLeastOnce())->method('getData')->willReturnMap($testData['observer.getData']);
     $this->resultMock->expects($this->once())->method('getData')->willReturn($testData['result.getData']);
     $orderMock->expects($this->atLeastOnce())->method('getIncrementId')->willReturn($testData['order.getIncrementId']);
     $this->sessionMock->expects($this->once())->method('addCheckoutOrderIncrementId')->with($testData['session.addCheckoutOrderIncrementId']);
     $this->sessionMock->expects($this->once())->method('setLastOrderIncrementId')->with($testData['session.setLastOrderIncrementId']);
     $orderPaymentMock->expects($this->once())->method('getMethodInstance')->willReturn($instanceMock);
     $instanceMock->expects($this->once())->method('generateRequestFromOrder')->with($orderMock)->willReturn($requestToAuthorizenetMock);
     $this->actionMock->expects($this->once())->method('getRequest')->willReturn($requestMock);
     $requestMock->expects($this->once())->method('getControllerName')->willReturn($testData['request.getControllerName']);
     $requestToAuthorizenetMock->expects($this->once())->method('setControllerActionName')->with($testData['requestToAuthorizenet.setControllerActionName']);
     $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
     $storeMock->expects($this->once())->method('isCurrentlySecure')->willReturn($testData['store.isCurrentlySecure']);
     $requestToAuthorizenetMock->expects($this->once())->method('setIsSecure')->with($testData['requestToAuthorizenet.setIsSecure']);
     $requestToAuthorizenetMock->expects($this->once())->method('getData')->willReturn($testData['requestToAuthorizenet.getData']);
     $this->resultMock->expects($this->once())->method('setData')->with($testData['result.setData']);
     $this->addFieldsToResponseObserver->execute($observerMock);
 }
Exemplo n.º 21
0
 /**
  * Edit CMS page
  *
  * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function execute()
 {
     // 1. Get ID and create model
     $id = $this->getRequest()->getParam('page_id');
     $model = $this->_objectManager->create('Magento\\Cms\\Model\\Page');
     // 2. Initial checking
     if ($id) {
         $model->load($id);
         if (!$model->getId()) {
             $this->messageManager->addError(__('This page no longer exists.'));
             /** \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
             $resultRedirect = $this->resultRedirectFactory->create();
             return $resultRedirect->setPath('*/*/');
         }
     }
     // 3. Set entered data if was error when we do save
     $data = $this->_objectManager->get('Magento\\Backend\\Model\\Session')->getFormData(true);
     if (!empty($data)) {
         $model->setData($data);
     }
     // 4. Register model to use later in blocks
     $this->_coreRegistry->register(RegistryConstants::CMS_PAGE, $model);
     // 5. Build edit form
     /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
     $resultPage = $this->_initAction();
     $resultPage->addBreadcrumb($id ? __('Edit Page') : __('New Page'), $id ? __('Edit Page') : __('New Page'));
     $resultPage->getConfig()->getTitle()->prepend(__('Pages'));
     $resultPage->getConfig()->getTitle()->prepend($model->getId() ? $model->getTitle() : __('New Page'));
     return $resultPage;
 }
Exemplo n.º 22
0
 /**
  * @param bool $canReturnToStock
  * @param bool $manageStock
  * @param bool $result
  * @dataProvider canReturnItemsToStockDataProvider
  */
 public function testCanReturnItemsToStock($canReturnToStock, $manageStock, $result)
 {
     $productId = 7;
     $property = new \ReflectionProperty($this->items, '_canReturnToStock');
     $property->setAccessible(true);
     $this->assertNull($property->getValue($this->items));
     $this->stockConfiguration->expects($this->once())->method('canSubtractQty')->will($this->returnValue($canReturnToStock));
     if ($canReturnToStock) {
         $orderItem = $this->getMock('Magento\\Sales\\Model\\Order\\Item', ['getProductId', '__wakeup', 'getStore'], [], '', false);
         $store = $this->getMock('Magento\\Store\\Model\\Store', ['getWebsiteId'], [], '', false);
         $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue(10));
         $orderItem->expects($this->any())->method('getStore')->will($this->returnValue($store));
         $orderItem->expects($this->once())->method('getProductId')->will($this->returnValue($productId));
         $creditMemoItem = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo\\Item', ['setCanReturnToStock', 'getOrderItem', '__wakeup'], [], '', false);
         $creditMemo = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo', [], [], '', false);
         $creditMemo->expects($this->once())->method('getAllItems')->will($this->returnValue([$creditMemoItem]));
         $creditMemoItem->expects($this->any())->method('getOrderItem')->will($this->returnValue($orderItem));
         $this->stockItemMock->expects($this->once())->method('getManageStock')->will($this->returnValue($manageStock));
         $creditMemoItem->expects($this->once())->method('setCanReturnToStock')->with($this->equalTo($manageStock))->will($this->returnSelf());
         $order = $this->getMock('Magento\\Sales\\Model\\Order', ['setCanReturnToStock', '__wakeup'], [], '', false);
         $order->expects($this->once())->method('setCanReturnToStock')->with($this->equalTo($manageStock))->will($this->returnSelf());
         $creditMemo->expects($this->once())->method('getOrder')->will($this->returnValue($order));
         $this->registryMock->expects($this->any())->method('registry')->with('current_creditmemo')->will($this->returnValue($creditMemo));
     }
     $this->assertSame($result, $this->items->canReturnItemsToStock());
     $this->assertSame($result, $property->getValue($this->items));
     // lazy load test
     $this->assertSame($result, $this->items->canReturnItemsToStock());
 }
Exemplo n.º 23
0
 public function testCanShowTabPositive()
 {
     $integrationData = $this->getFixtureIntegration()->getData();
     $integrationData[Integration::SETUP_TYPE] = Integration::TYPE_CONFIG;
     $this->registry->register(IntegrationController::REGISTRY_KEY_CURRENT_INTEGRATION, $integrationData);
     $this->assertTrue($this->createApiTabBlock()->canShowTab());
 }
Exemplo n.º 24
0
 public function testToOptionArray()
 {
     $inputTypesSet = [['value' => 'text', 'label' => 'Text Field'], ['value' => 'textarea', 'label' => 'Text Area'], ['value' => 'date', 'label' => 'Date'], ['value' => 'boolean', 'label' => 'Yes/No'], ['value' => 'multiselect', 'label' => 'Multiple Select'], ['value' => 'select', 'label' => 'Dropdown'], ['value' => 'price', 'label' => 'Price'], ['value' => 'media_image', 'label' => 'Media Image']];
     $this->registry->expects($this->once())->method('registry');
     $this->registry->expects($this->once())->method('register');
     $this->assertEquals($inputTypesSet, $this->inputtypeModel->toOptionArray());
 }
Exemplo n.º 25
0
 /**
  * @return Product
  */
 public function getProduct()
 {
     if (!$this->_product) {
         $this->_product = $this->_coreRegistry->registry('product');
     }
     return $this->_product;
 }
Exemplo n.º 26
0
 /**
  * @return void
  */
 public function execute()
 {
     $this->_title->add(__('Search Terms'));
     $id = $this->getRequest()->getParam('id');
     $model = $this->_objectManager->create('Magento\\CatalogSearch\\Model\\Query');
     if ($id) {
         $model->load($id);
         if (!$model->getId()) {
             $this->messageManager->addError(__('This search no longer exists.'));
             $this->_redirect('catalog/*');
             return;
         }
     }
     // set entered data if was error when we do save
     $data = $this->_objectManager->get('Magento\\Backend\\Model\\Session')->getPageData(true);
     if (!empty($data)) {
         $model->addData($data);
     }
     $this->_coreRegistry->register('current_catalog_search', $model);
     $this->_initAction();
     $this->_title->add($id ? $model->getQueryText() : __('New Search'));
     $this->_view->getLayout()->getBlock('head')->setCanLoadRulesJs(true);
     $this->_view->getLayout()->getBlock('adminhtml.catalog.search.edit')->setData('action', $this->getUrl('catalog/search/save'));
     $this->_addBreadcrumb($id ? __('Edit Search') : __('New Search'), $id ? __('Edit Search') : __('New Search'));
     $this->_view->renderLayout();
 }
Exemplo n.º 27
0
 /**
  * Edit Testimonial
  *
  * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function execute()
 {
     $id = $this->getRequest()->getParam('testimonial_id');
     $model = $this->_objectManager->create('V3N0m21\\Testimonials\\Model\\Testimonial');
     if ($id) {
         $model->load($id);
         if (!$model->getId()) {
             $this->messageManager->addError(__('This testimonial no longer exists.'));
             /** \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
             $resultRedirect = $this->resultRedirectFactory->create();
             return $resultRedirect->setPath('*/*/');
         }
     }
     $data = $this->_objectManager->get('Magento\\Backend\\Model\\Session')->getFormData(true);
     if (!empty($data)) {
         $model->setData($data);
     }
     $this->_coreRegistry->register('testimonials_testimonial', $model);
     /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
     $resultPage = $this->_initAction();
     $resultPage->addBreadcrumb($id ? __('Edit Testimonial') : __('New Testimonial'), $id ? __('Edit Testimonial') : __('New Testimonial'));
     $resultPage->getConfig()->getTitle()->prepend(__('Testimonials'));
     $resultPage->getConfig()->getTitle()->prepend($model->getId() ? $model->getTitle() : __('New Testimonial'));
     return $resultPage;
 }
Exemplo n.º 28
0
 public function testGetLinkData()
 {
     $expectingFileData = ['file' => ['file' => 'file/link.gif', 'name' => '<a href="final_url">link.gif</a>', 'size' => '1.1', 'status' => 'old'], 'sample_file' => ['file' => 'file/sample.gif', 'name' => '<a href="final_url">sample.gif</a>', 'size' => '1.1', 'status' => 'old']];
     $this->productModel->expects($this->any())->method('getTypeId')->will($this->returnValue('downloadable'));
     $this->productModel->expects($this->any())->method('getTypeInstance')->will($this->returnValue($this->downloadableProductModel));
     $this->productModel->expects($this->any())->method('getStoreId')->will($this->returnValue(0));
     $this->downloadableProductModel->expects($this->any())->method('getLinks')->will($this->returnValue([$this->downloadableLinkModel]));
     $this->coreRegistry->expects($this->any())->method('registry')->will($this->returnValue($this->productModel));
     $this->downloadableLinkModel->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->downloadableLinkModel->expects($this->any())->method('getTitle')->will($this->returnValue('Link Title'));
     $this->downloadableLinkModel->expects($this->any())->method('getPrice')->will($this->returnValue('10'));
     $this->downloadableLinkModel->expects($this->any())->method('getNumberOfDownloads')->will($this->returnValue('6'));
     $this->downloadableLinkModel->expects($this->any())->method('getLinkUrl')->will($this->returnValue(null));
     $this->downloadableLinkModel->expects($this->any())->method('getLinkType')->will($this->returnValue('file'));
     $this->downloadableLinkModel->expects($this->any())->method('getSampleFile')->will($this->returnValue('file/sample.gif'));
     $this->downloadableLinkModel->expects($this->any())->method('getSampleType')->will($this->returnValue('file'));
     $this->downloadableLinkModel->expects($this->any())->method('getSortOrder')->will($this->returnValue(0));
     $this->downloadableLinkModel->expects($this->any())->method('getLinkFile')->will($this->returnValue('file/link.gif'));
     $this->downloadableLinkModel->expects($this->any())->method('getStoreTitle')->will($this->returnValue('Store Title'));
     $this->escaper->expects($this->any())->method('escapeHtml')->will($this->returnValue('Link Title'));
     $this->fileHelper->expects($this->any())->method('getFilePath')->will($this->returnValue('/file/path/link.gif'));
     $this->fileHelper->expects($this->any())->method('ensureFileInFilesystem')->will($this->returnValue(true));
     $this->fileHelper->expects($this->any())->method('getFileSize')->will($this->returnValue('1.1'));
     $this->urlBuilder->expects($this->any())->method('getUrl')->will($this->returnValue('final_url'));
     $linkData = $this->block->getLinkData();
     foreach ($linkData as $link) {
         $fileSave = $link->getFileSave(0);
         $sampleFileSave = $link->getSampleFileSave(0);
         $this->assertEquals($expectingFileData['file'], $fileSave);
         $this->assertEquals($expectingFileData['sample_file'], $sampleFileSave);
     }
 }
Exemplo n.º 29
0
 /**
  * @return $this
  */
 protected function _prepareCollection()
 {
     /** @var $collection \Magento\Newsletter\Model\Resource\Queue\Collection */
     $collection = $this->_collectionFactory->create()->addTemplateInfo()->addSubscriberFilter($this->_coreRegistry->registry('subscriber')->getId());
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
 /**
  * @param \Magento\Framework\Controller\ResultInterface $subject
  * @param callable $proceed
  * @param ResponseHttp $response
  * @return \Magento\Framework\Controller\ResultInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundRenderResult(\Magento\Framework\Controller\ResultInterface $subject, \Closure $proceed, ResponseHttp $response)
 {
     $result = $proceed($response);
     $usePlugin = $this->registry->registry('use_page_cache_plugin');
     if (!$usePlugin || !$this->config->isEnabled() || $this->config->getType() != \Magento\PageCache\Model\Config::BUILT_IN) {
         return $result;
     }
     if ($this->state->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
         $cacheControlHeader = $response->getHeader('Cache-Control');
         if ($cacheControlHeader instanceof \Zend\Http\Header\HeaderInterface) {
             $response->setHeader('X-Magento-Cache-Control', $cacheControlHeader->getFieldValue());
         }
         $response->setHeader('X-Magento-Cache-Debug', 'MISS', true);
     }
     $tagsHeader = $response->getHeader('X-Magento-Tags');
     $tags = [];
     if ($tagsHeader) {
         $tags = explode(',', $tagsHeader->getFieldValue());
         $response->clearHeader('X-Magento-Tags');
     }
     $tags = array_unique(array_merge($tags, [\Magento\PageCache\Model\Cache\Type::CACHE_TAG]));
     $response->setHeader('X-Magento-Tags', implode(',', $tags));
     $this->kernel->process($response);
     return $result;
 }