Esempio n. 1
0
 /**
  * Attributes validation action
  *
  * @return void
  */
 public function execute()
 {
     $response = new \Magento\Framework\Object();
     $response->setError(false);
     $attributesData = $this->getRequest()->getParam('attributes', array());
     $data = new \Magento\Framework\Object();
     try {
         if ($attributesData) {
             foreach ($attributesData as $attributeCode => $value) {
                 $attribute = $this->_objectManager->get('Magento\\Eav\\Model\\Config')->getAttribute('catalog_product', $attributeCode);
                 if (!$attribute->getAttributeId()) {
                     unset($attributesData[$attributeCode]);
                     continue;
                 }
                 $data->setData($attributeCode, $value);
                 $attribute->getBackend()->validate($data);
             }
         }
     } catch (\Magento\Eav\Model\Entity\Attribute\Exception $e) {
         $response->setError(true);
         $response->setAttribute($e->getAttributeCode());
         $response->setMessage($e->getMessage());
     } catch (\Magento\Framework\Model\Exception $e) {
         $response->setError(true);
         $response->setMessage($e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('Something went wrong while updating the product(s) attributes.'));
         $this->_view->getLayout()->initMessages();
         $response->setError(true);
         $response->setHtmlMessage($this->_view->getLayout()->getMessagesBlock()->getGroupedHtml());
     }
     $this->getResponse()->representJson($response->toJson());
 }
Esempio n. 2
0
 /**
  * Prepare and do request to shipment
  *
  * @param Shipment $orderShipment
  * @return \Magento\Framework\Object
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function requestToShipment(Shipment $orderShipment)
 {
     $admin = $this->_authSession->getUser();
     $order = $orderShipment->getOrder();
     $address = $order->getShippingAddress();
     $shippingMethod = $order->getShippingMethod(true);
     $shipmentStoreId = $orderShipment->getStoreId();
     $shipmentCarrier = $this->_carrierFactory->create($order->getShippingMethod(true)->getCarrierCode());
     $baseCurrencyCode = $this->_storeManager->getStore($shipmentStoreId)->getBaseCurrencyCode();
     if (!$shipmentCarrier) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Invalid carrier: %1', $shippingMethod->getCarrierCode()));
     }
     $shipperRegionCode = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_REGION_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId);
     if (is_numeric($shipperRegionCode)) {
         $shipperRegionCode = $this->_regionFactory->create()->load($shipperRegionCode)->getCode();
     }
     $recipientRegionCode = $this->_regionFactory->create()->load($address->getRegionId())->getCode();
     $originStreet1 = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ADDRESS1, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId);
     $originStreet2 = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ADDRESS2, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId);
     $storeInfo = new \Magento\Framework\Object((array) $this->_scopeConfig->getValue('general/store_information', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId));
     if (!$admin->getFirstname() || !$admin->getLastname() || !$storeInfo->getName() || !$storeInfo->getPhone() || !$originStreet1 || !$shipperRegionCode || !$this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_CITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId) || !$this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ZIP, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId) || !$this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_COUNTRY_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('We don\'t have enough information to create shipping labels. Please make sure your store information and settings are complete.'));
     }
     /** @var $request \Magento\Shipping\Model\Shipment\Request */
     $request = $this->_shipmentRequestFactory->create();
     $request->setOrderShipment($orderShipment);
     $request->setShipperContactPersonName($admin->getName());
     $request->setShipperContactPersonFirstName($admin->getFirstname());
     $request->setShipperContactPersonLastName($admin->getLastname());
     $request->setShipperContactCompanyName($storeInfo->getName());
     $request->setShipperContactPhoneNumber($storeInfo->getPhone());
     $request->setShipperEmail($admin->getEmail());
     $request->setShipperAddressStreet(trim($originStreet1 . ' ' . $originStreet2));
     $request->setShipperAddressStreet1($originStreet1);
     $request->setShipperAddressStreet2($originStreet2);
     $request->setShipperAddressCity($this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_CITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId));
     $request->setShipperAddressStateOrProvinceCode($shipperRegionCode);
     $request->setShipperAddressPostalCode($this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ZIP, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId));
     $request->setShipperAddressCountryCode($this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_COUNTRY_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId));
     $request->setRecipientContactPersonName(trim($address->getFirstname() . ' ' . $address->getLastname()));
     $request->setRecipientContactPersonFirstName($address->getFirstname());
     $request->setRecipientContactPersonLastName($address->getLastname());
     $request->setRecipientContactCompanyName($address->getCompany());
     $request->setRecipientContactPhoneNumber($address->getTelephone());
     $request->setRecipientEmail($address->getEmail());
     $request->setRecipientAddressStreet(trim($address->getStreetLine(1) . ' ' . $address->getStreetLine(2)));
     $request->setRecipientAddressStreet1($address->getStreetLine(1));
     $request->setRecipientAddressStreet2($address->getStreetLine(2));
     $request->setRecipientAddressCity($address->getCity());
     $request->setRecipientAddressStateOrProvinceCode($address->getRegionCode());
     $request->setRecipientAddressRegionCode($recipientRegionCode);
     $request->setRecipientAddressPostalCode($address->getPostcode());
     $request->setRecipientAddressCountryCode($address->getCountryId());
     $request->setShippingMethod($shippingMethod->getMethod());
     $request->setPackageWeight($order->getWeight());
     $request->setPackages($orderShipment->getPackages());
     $request->setBaseCurrencyCode($baseCurrencyCode);
     $request->setStoreId($shipmentStoreId);
     return $shipmentCarrier->requestToShipment($request);
 }
Esempio n. 3
0
 /**
  * Creates a collection item that represents a customer for the customer Grid.
  *
  * @param CustomerDetails $customerDetail Input data for creating the item.
  * @return \Magento\Framework\Object Collection item that represents a customer
  */
 protected function createCustomerDetailItem(CustomerDetails $customerDetail)
 {
     $customer = $customerDetail->getCustomer();
     $customerNameParts = array($customer->getPrefix(), $customer->getFirstname(), $customer->getMiddlename(), $customer->getLastname(), $customer->getSuffix());
     $customerItem = new \Magento\Framework\Object();
     $customerItem->setId($customer->getId());
     $customerItem->setEntityId($customer->getId());
     // All parts of the customer name must be displayed in the name column of the grid
     $customerItem->setName(implode(' ', array_filter($customerNameParts)));
     $customerItem->setEmail($customer->getEmail());
     $customerItem->setWebsiteId($customer->getWebsiteId());
     $customerItem->setCreatedAt($customer->getCreatedAt());
     $customerItem->setGroupId($customer->getGroupId());
     $billingAddress = null;
     foreach ($customerDetail->getAddresses() as $address) {
         if ($address->isDefaultBilling()) {
             $billingAddress = $address;
             break;
         }
     }
     if ($billingAddress !== null) {
         $customerItem->setBillingTelephone($billingAddress->getTelephone());
         $customerItem->setBillingPostcode($billingAddress->getPostcode());
         $customerItem->setBillingCountryId($billingAddress->getCountryId());
         $region = is_null($billingAddress->getRegion()) ? '' : $billingAddress->getRegion()->getRegion();
         $customerItem->setBillingRegion($region);
     }
     return $customerItem;
 }
Esempio n. 4
0
 public function testGetWysiwygPluginSettings()
 {
     $jsPluginSourceUrl = 'js-plugin-source';
     $actionUrl = 'action-url';
     $assetRepoMock = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\Repository')->disableOriginalConstructor()->getMock();
     $urlMock = $this->getMockBuilder('Magento\\Backend\\Model\\UrlInterface')->disableOriginalConstructor()->getMock();
     $assetRepoMock->expects($this->any())->method('getUrl')->willReturn($jsPluginSourceUrl);
     $urlMock->expects($this->any())->method('getUrl')->willReturn($actionUrl);
     // Set up SUT
     $args = ['assetRepo' => $assetRepoMock, 'url' => $urlMock];
     $model = (new ObjectManager($this))->getObject('Magento\\Variable\\Model\\Variable\\Config', $args);
     $customKey = 'key';
     $customVal = 'val';
     $configObject = new \Magento\Framework\Object();
     $configObject->setPlugins([[$customKey => $customVal]]);
     $variablePluginConfig = $model->getWysiwygPluginSettings($configObject)['plugins'];
     $customPluginConfig = $variablePluginConfig[0];
     $addedPluginConfig = $variablePluginConfig[1];
     // Verify custom plugin config is present
     $this->assertSame($customVal, $customPluginConfig[$customKey]);
     // Verify added plugin config is present
     $this->assertContains($actionUrl, $addedPluginConfig['options']['onclick']['subject']);
     $this->assertContains($actionUrl, $addedPluginConfig['options']['url']);
     $this->assertContains($jsPluginSourceUrl, $addedPluginConfig['src']);
 }
 /**
  * Creates a collection item that represents a featuretoggle for the features Grid.
  *
  * @param FeaturetoggleInterface $featuretoggle Input data for creating the item.
  * @return \Magento\Framework\Object Collection item that represents a warehouse
  */
 protected function createFeaturetoggleItem(FeaturetoggleInterface $featuretoggle)
 {
     $featuretoggleItem = new \Magento\Framework\Object();
     $featuretoggleItem->setFeaturetoggleId($featuretoggle->getFeaturetoggleId());
     $featuretoggleItem->setName($featuretoggle->getName());
     return $featuretoggleItem;
 }
 /**
  * Add attribute to product template
  *
  * @return \Magento\Framework\Controller\Result\Json
  */
 public function execute()
 {
     $request = $this->getRequest();
     $resultJson = $this->resultJsonFactory->create();
     try {
         /** @var \Magento\Eav\Model\Entity\Attribute $attribute */
         $attribute = $this->_objectManager->create('Magento\\Eav\\Model\\Entity\\Attribute')->load($request->getParam('attribute_id'));
         $attributeSet = $this->_objectManager->create('Magento\\Eav\\Model\\Entity\\Attribute\\Set')->load($request->getParam('template_id'));
         /** @var \Magento\Eav\Model\Resource\Entity\Attribute\Group\Collection $attributeGroupCollection */
         $attributeGroupCollection = $this->_objectManager->get('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Group\\Collection');
         $attributeGroupCollection->setAttributeSetFilter($attributeSet->getId());
         $attributeGroupCollection->addFilter('attribute_group_code', $request->getParam('group'));
         $attributeGroupCollection->setPageSize(1);
         $attributeGroup = $attributeGroupCollection->getFirstItem();
         $attribute->setAttributeSetId($attributeSet->getId())->loadEntityAttributeIdBySet();
         $attribute->setAttributeSetId($request->getParam('template_id'))->setAttributeGroupId($attributeGroup->getId())->setSortOrder('0')->save();
         $resultJson->setJsonData($attribute->toJson());
     } catch (\Exception $e) {
         $response = new \Magento\Framework\Object();
         $response->setError(false);
         $response->setMessage($e->getMessage());
         $resultJson->setJsonData($response->toJson());
     }
     return $resultJson;
 }
Esempio n. 7
0
 /**
  * Action to reconfigure cart item
  *
  * @return \Magento\Framework\View\Result\Page|\Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     // Extract item and product to configure
     $id = (int) $this->getRequest()->getParam('id');
     $productId = (int) $this->getRequest()->getParam('product_id');
     $quoteItem = null;
     if ($id) {
         $quoteItem = $this->cart->getQuote()->getItemById($id);
     }
     try {
         if (!$quoteItem || $productId != $quoteItem->getProduct()->getId()) {
             $this->messageManager->addError(__("We can't find the quote item."));
             return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('checkout/cart');
         }
         $params = new \Magento\Framework\Object();
         $params->setCategoryId(false);
         $params->setConfigureMode(true);
         $params->setBuyRequest($quoteItem->getBuyRequest());
         $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
         $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\View')->prepareAndRender($resultPage, $quoteItem->getProduct()->getId(), $this, $params);
         return $resultPage;
     } catch (\Exception $e) {
         $this->messageManager->addError(__('We cannot configure the product.'));
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         return $this->_goBack();
     }
 }
Esempio n. 8
0
 /**
  * Update attribute values for entity list per store
  *
  * @param array $entityIds
  * @param array $attrData
  * @param int $storeId
  * @return $this
  * @throws \Exception
  */
 public function updateAttributes($entityIds, $attrData, $storeId)
 {
     $object = new \Magento\Framework\Object();
     $object->setIdFieldName('entity_id')->setStoreId($storeId);
     $this->_getWriteAdapter()->beginTransaction();
     try {
         foreach ($attrData as $attrCode => $value) {
             $attribute = $this->getAttribute($attrCode);
             if (!$attribute->getAttributeId()) {
                 continue;
             }
             $i = 0;
             foreach ($entityIds as $entityId) {
                 $i++;
                 $object->setId($entityId);
                 // collect data for save
                 $this->_saveAttributeValue($object, $attribute, $value);
                 // save collected data every 1000 rows
                 if ($i % 1000 == 0) {
                     $this->_processAttributeValues();
                 }
             }
             $this->_processAttributeValues();
         }
         $this->_getWriteAdapter()->commit();
     } catch (\Exception $e) {
         $this->_getWriteAdapter()->rollBack();
         throw $e;
     }
     return $this;
 }
Esempio n. 9
0
 /**
  * AJAX customer validation action
  *
  * @return void
  */
 public function execute()
 {
     $response = new \Magento\Framework\Object();
     $response->setError(0);
     $errors = null;
     $userId = (int) $this->getRequest()->getParam('user_id');
     $data = $this->getRequest()->getPost();
     try {
         /** @var $model \Magento\User\Model\User */
         $model = $this->_userFactory->create()->load($userId);
         $model->setData($this->_getAdminUserData($data));
         $errors = $model->validate();
     } catch (\Magento\Framework\Model\Exception $exception) {
         /* @var $error Error */
         foreach ($exception->getMessages(\Magento\Framework\Message\MessageInterface::TYPE_ERROR) as $error) {
             $errors[] = $error->getText();
         }
     }
     if ($errors !== true && !empty($errors)) {
         foreach ($errors as $error) {
             $this->messageManager->addError($error);
         }
         $response->setError(1);
         $this->_view->getLayout()->initMessages();
         $response->setHtmlMessage($this->_view->getLayout()->getMessagesBlock()->getGroupedHtml());
     }
     $this->getResponse()->representJson($response->toJson());
 }
Esempio n. 10
0
 /**
  * @covers \Magento\Email\Block\Adminhtml\Template\Grid\Renderer\Sender::render
  */
 public function testRenderNameAndEmail()
 {
     $row = new \Magento\Framework\Object();
     $row->setTemplateSenderName('Sender Name');
     $row->setTemplateSenderEmail('Sender Email');
     $this->assertEquals('Sender Name [Sender Email]', $this->sender->render($row));
 }
Esempio n. 11
0
 /**
  * Action to reconfigure cart item
  *
  * @return void
  */
 public function execute()
 {
     // Extract item and product to configure
     $id = (int) $this->getRequest()->getParam('id');
     $quoteItem = null;
     if ($id) {
         $quoteItem = $this->cart->getQuote()->getItemById($id);
     }
     if (!$quoteItem) {
         $this->messageManager->addError(__("We can't find the quote item."));
         $this->_redirect('checkout/cart');
         return;
     }
     try {
         $params = new \Magento\Framework\Object();
         $params->setCategoryId(false);
         $params->setConfigureMode(true);
         $params->setBuyRequest($quoteItem->getBuyRequest());
         $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\View')->prepareAndRender($quoteItem->getProduct()->getId(), $this, $params);
     } catch (\Exception $e) {
         $this->messageManager->addError(__('We cannot configure the product.'));
         $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e);
         $this->_goBack();
         return;
     }
 }
Esempio n. 12
0
 public function testFactory()
 {
     $product = new \Magento\Framework\Object();
     $product->setTypeId(\Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE);
     $type = $this->_productType->factory($product);
     $this->assertInstanceOf('\\Magento\\GroupedProduct\\Model\\Product\\Type\\Grouped', $type);
 }
Esempio n. 13
0
 /**
  * Prepare page object
  *
  * @param array $data
  * @return \Magento\Framework\Object
  */
 protected function _prepareObject(array $data)
 {
     $object = new \Magento\Framework\Object();
     $object->setId($data[$this->getIdFieldName()]);
     $object->setUrl($data['url']);
     $object->setUpdatedAt($data['updated_at']);
     return $object;
 }
Esempio n. 14
0
 /**
  * Assign data to info model instance
  *
  * @param \Magento\Framework\Object|mixed $data
  * @return $this
  */
 public function assignData($data)
 {
     if (!$data instanceof \Magento\Framework\Object) {
         $data = new \Magento\Framework\Object($data);
     }
     $this->getInfoInstance()->setPoNumber($data->getPoNumber());
     return $this;
 }
Esempio n. 15
0
 /**
  * Initialize requested product object
  *
  * @return ModelProduct
  */
 protected function _initProduct()
 {
     $categoryId = (int) $this->getRequest()->getParam('category', false);
     $productId = (int) $this->getRequest()->getParam('id');
     $params = new \Magento\Framework\Object();
     $params->setCategoryId($categoryId);
     return $this->_objectManager->get('Magento\\Catalog\\Helper\\Product')->initProduct($productId, $this, $params);
 }
Esempio n. 16
0
 /**
  * Edit category page
  *
  * @return void
  */
 public function execute()
 {
     $storeId = (int) $this->getRequest()->getParam('store');
     $parentId = (int) $this->getRequest()->getParam('parent');
     $categoryId = (int) $this->getRequest()->getParam('id');
     if ($storeId && !$categoryId && !$parentId) {
         $store = $this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore($storeId);
         $this->getRequest()->setParam('id', (int) $store->getRootCategoryId());
     }
     $category = $this->_initCategory(true);
     if (!$category) {
         return;
     }
     $this->_title->add($categoryId ? $category->getName() : __('Categories'));
     /**
      * Check if we have data in session (if during category save was exception)
      */
     $data = $this->_getSession()->getCategoryData(true);
     if (isset($data['general'])) {
         $category->addData($data['general']);
     }
     /**
      * Build response for ajax request
      */
     if ($this->getRequest()->getQuery('isAjax')) {
         // prepare breadcrumbs of selected category, if any
         $breadcrumbsPath = $category->getPath();
         if (empty($breadcrumbsPath)) {
             // but if no category, and it is deleted - prepare breadcrumbs from path, saved in session
             $breadcrumbsPath = $this->_objectManager->get('Magento\\Backend\\Model\\Auth\\Session')->getDeletedPath(true);
             if (!empty($breadcrumbsPath)) {
                 $breadcrumbsPath = explode('/', $breadcrumbsPath);
                 // no need to get parent breadcrumbs if deleting category level 1
                 if (count($breadcrumbsPath) <= 1) {
                     $breadcrumbsPath = '';
                 } else {
                     array_pop($breadcrumbsPath);
                     $breadcrumbsPath = implode('/', $breadcrumbsPath);
                 }
             }
         }
         $this->_view->loadLayout();
         $eventResponse = new \Magento\Framework\Object(array('content' => $this->_view->getLayout()->getBlock('category.edit')->getFormHtml() . $this->_view->getLayout()->getBlock('category.tree')->getBreadcrumbsJavascript($breadcrumbsPath, 'editingCategoryBreadcrumbs'), 'messages' => $this->_view->getLayout()->getMessagesBlock()->getGroupedHtml()));
         $this->_eventManager->dispatch('category_prepare_ajax_response', array('response' => $eventResponse, 'controller' => $this));
         $this->getResponse()->setHeader('Content-type', 'application/json', true);
         $this->getResponse()->representJson($this->_objectManager->get('Magento\\Core\\Helper\\Data')->jsonEncode($eventResponse->getData()));
         return;
     }
     $this->_view->loadLayout();
     $this->_setActiveMenu('Magento_Catalog::catalog_categories');
     $this->_view->getLayout()->getBlock('head')->setCanLoadExtJs(true)->setContainerCssClass('catalog-categories');
     $this->_addBreadcrumb(__('Manage Catalog Categories'), __('Manage Categories'));
     $block = $this->_view->getLayout()->getBlock('catalog.wysiwyg.js');
     if ($block) {
         $block->setStoreId($storeId);
     }
     $this->_view->renderLayout();
 }
Esempio n. 17
0
 /**
  * @param array $data
  * @param bool $result
  * @param array $messages
  *
  * @covers \Magento\Framework\View\Design\Theme\Validator::validate
  * @dataProvider dataProviderValidate
  */
 public function testValidate(array $data, $result, array $messages)
 {
     /** @var $themeMock \Magento\Framework\Object */
     $themeMock = new \Magento\Framework\Object();
     $themeMock->setData($data);
     $validator = new \Magento\Framework\View\Design\Theme\Validator();
     $this->assertEquals($result, $validator->validate($themeMock));
     $this->assertEquals($messages, $validator->getErrorMessages());
 }
Esempio n. 18
0
 /**
  * Test hasRedirectOptions
  *
  * @dataProvider redirectOptionsDataProvider
  */
 public function testHasRedirectOptions($option, $expected)
 {
     $optionsMock = $this->getMock('Magento\\UrlRewrite\\Model\\UrlRewrite\\OptionProvider', array('getRedirectOptions'), array(), '', false, false);
     $optionsMock->expects($this->any())->method('getRedirectOptions')->will($this->returnValue(array('R', 'RP')));
     $helper = new \Magento\UrlRewrite\Helper\UrlRewrite($this->getMock('Magento\\Framework\\App\\Helper\\Context', array(), array(), '', false, false), $optionsMock);
     $mockObject = new \Magento\Framework\Object();
     $mockObject->setOptions($option);
     $this->assertEquals($expected, $helper->hasRedirectOptions($mockObject));
 }
Esempio n. 19
0
    /**
     * Tests \Magento\Framework\Object->__construct()
     */
    public function testConstruct()
    {
        $object = new \Magento\Framework\Object();
        $this->assertEquals([], $object->getData());

        $data = ['test' => 'test'];
        $object = new \Magento\Framework\Object($data);
        $this->assertEquals($data, $object->getData());
    }
Esempio n. 20
0
 /**
  * @covers \Magento\Email\Block\Adminhtml\Template\Grid\Renderer\Action::render
  */
 public function testRender()
 {
     $this->columnMock->expects($this->once())->method('setActions');
     $this->columnMock->expects($this->once())->method('getActions')->willReturn(['url', 'popup', 'caption']);
     $this->action->setColumn($this->columnMock);
     $row = new \Magento\Framework\Object();
     $row->setId(1);
     $this->assertContains('admin__control-select', $this->action->render($row));
 }
Esempio n. 21
0
 /**
  * Prepare response object and dispatch prepare price event
  * Return response object
  *
  * @param \Magento\Framework\DB\Select $select
  * @return \Magento\Framework\Object
  */
 protected function _dispatchPreparePriceEvent($select)
 {
     // prepare response object for event
     $response = new \Magento\Framework\Object();
     $response->setAdditionalCalculations(array());
     // prepare event arguments
     $eventArgs = array('select' => $select, 'table' => 'price_index', 'store_id' => $this->_storeManager->getStore()->getId(), 'response_object' => $response);
     $this->_eventManager->dispatch('catalog_prepare_price_select', $eventArgs);
     return $response;
 }
Esempio n. 22
0
 /**
  * Creates and inits block
  *
  * @param string|null $reportType
  * @return \Magento\Reports\Block\Adminhtml\Sales\Refunded\Grid
  */
 protected function _createBlock($reportType = null)
 {
     $block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Reports\\Block\\Adminhtml\\Sales\\Refunded\\Grid');
     $filterData = new \Magento\Framework\Object();
     if ($reportType) {
         $filterData->setReportType($reportType);
     }
     $block->setFilterData($filterData);
     return $block;
 }
Esempio n. 23
0
 /**
  * @param array $actions
  * @return string
  */
 protected function _actionsToHtml(array $actions)
 {
     $html = [];
     $attributesObject = new \Magento\Framework\Object();
     foreach ($actions as $action) {
         $attributesObject->setData($action['@']);
         $html[] = '<a ' . $attributesObject->serialize() . '>' . $action['#'] . '</a>';
     }
     return implode('<span class="separator">&nbsp;|&nbsp;</span>', $html);
 }
Esempio n. 24
0
 /**
  * @param sring|null $typeId
  * @dataProvider factoryReturnsSingletonDataProvider
  */
 public function testFactoryReturnsSingleton($typeId)
 {
     $product = new \Magento\Framework\Object();
     if ($typeId) {
         $product->setTypeId($typeId);
     }
     $type = $this->_productType->factory($product);
     $otherType = $this->_productType->factory($product);
     $this->assertSame($otherType, $type);
 }
Esempio n. 25
0
 protected function setUp()
 {
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->testData = ['before_element_html' => 'test_before_element_html', 'html_id' => 'test_id', 'name' => 'test_name', 'value' => 'test_value', 'title' => 'test_title', 'disabled' => true, 'after_element_js' => 'test_after_element_js', 'after_element_html' => 'test_after_element_html', 'html_id_prefix' => 'test_id_prefix_', 'html_id_suffix' => '_test_id_suffix'];
     $this->file = $objectManager->getObject('Magento\\Config\\Block\\System\\Config\\Form\\Field\\File', ['data' => $this->testData]);
     $formMock = new \Magento\Framework\Object();
     $formMock->setHtmlIdPrefix($this->testData['html_id_prefix']);
     $formMock->setHtmlIdSuffix($this->testData['html_id_suffix']);
     $this->file->setForm($formMock);
 }
Esempio n. 26
0
 public function testRenderConfigureResultNotOK()
 {
     $configureResult = new \Magento\Framework\Object();
     $configureResult->setError(true)->setMessage('Test Message');
     $this->helper->renderConfigureResult($configureResult);
     $customerId = $this->registry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
     $this->assertNull($customerId);
     $errorMessage = $this->registry->registry('composite_configure_result_error_message');
     $this->assertEquals('Test Message', $errorMessage);
 }
Esempio n. 27
0
 /**
  * Ajax handler to response configuration fieldset of composite product in quote items
  *
  * @return void
  */
 public function execute()
 {
     // Prepare data
     $configureResult = new \Magento\Framework\Object();
     try {
         $quoteItemId = (int) $this->getRequest()->getParam('id');
         if (!$quoteItemId) {
             throw new \Magento\Framework\Model\Exception(__('Quote item id is not received.'));
         }
         $quoteItem = $this->_objectManager->create('Magento\\Sales\\Model\\Quote\\Item')->load($quoteItemId);
         if (!$quoteItem->getId()) {
             throw new \Magento\Framework\Model\Exception(__('Quote item is not loaded.'));
         }
         $configureResult->setOk(true);
         $optionCollection = $this->_objectManager->create('Magento\\Sales\\Model\\Quote\\Item\\Option')->getCollection()->addItemFilter(array($quoteItemId));
         $quoteItem->setOptions($optionCollection->getOptionsByItem($quoteItem));
         $configureResult->setBuyRequest($quoteItem->getBuyRequest());
         $configureResult->setCurrentStoreId($quoteItem->getStoreId());
         $configureResult->setProductId($quoteItem->getProductId());
         $sessionQuote = $this->_objectManager->get('Magento\\Backend\\Model\\Session\\Quote');
         $configureResult->setCurrentCustomerId($sessionQuote->getCustomerId());
     } catch (\Exception $e) {
         $configureResult->setError(true);
         $configureResult->setMessage($e->getMessage());
     }
     // Render page
     $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\Composite')->renderConfigureResult($configureResult);
 }
Esempio n. 28
0
 protected function setUp()
 {
     $factoryMock = $this->getMock('\\Magento\\Framework\\Data\\Form\\Element\\Factory', [], [], '', false);
     $collectionFactoryMock = $this->getMock('\\Magento\\Framework\\Data\\Form\\Element\\CollectionFactory', [], [], '', false);
     $escaperMock = $this->getMock('\\Magento\\Framework\\Escaper', [], [], '', false);
     $this->_model = new \Magento\Framework\Data\Form\Element\Textarea($factoryMock, $collectionFactoryMock, $escaperMock);
     $formMock = new \Magento\Framework\Object();
     $formMock->getHtmlIdPrefix('id_prefix');
     $formMock->getHtmlIdPrefix('id_suffix');
     $this->_model->setForm($formMock);
 }
Esempio n. 29
0
 protected function setUp()
 {
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->urlBuilderMock = $this->getMock('Magento\\Framework\\Url', [], [], '', false);
     $this->image = $objectManager->getObject('Magento\\Config\\Block\\System\\Config\\Form\\Field\\Image', ['urlBuilder' => $this->urlBuilderMock]);
     $this->testData = ['html_id_prefix' => 'test_id_prefix_', 'html_id' => 'test_id', 'html_id_suffix' => '_test_id_suffix', 'path' => 'catalog/product/placeholder', 'value' => 'test_value'];
     $formMock = new \Magento\Framework\Object();
     $formMock->setHtmlIdPrefix($this->testData['html_id_prefix']);
     $formMock->setHtmlIdSuffix($this->testData['html_id_suffix']);
     $this->image->setForm($formMock);
 }
Esempio n. 30
0
 /**
  * @return array
  */
 protected function _getAdditionalElementTypes()
 {
     $result = ['price' => 'Magento\\Catalog\\Block\\Adminhtml\\Product\\Helper\\Form\\Price', 'image' => 'Magento\\Catalog\\Block\\Adminhtml\\Product\\Helper\\Form\\Image', 'boolean' => 'Magento\\Catalog\\Block\\Adminhtml\\Product\\Helper\\Form\\Boolean'];
     $response = new \Magento\Framework\Object();
     $response->setTypes([]);
     $this->_eventManager->dispatch('adminhtml_catalog_product_edit_element_types', ['response' => $response]);
     foreach ($response->getTypes() as $typeName => $typeClass) {
         $result[$typeName] = $typeClass;
     }
     return $result;
 }