/** * Get options. * * @return array */ public function toOptionArray() { $fields = []; $fields[] = ['value' => '0', 'label' => '-- Disabled --']; $websiteName = $this->request->getParam('website', false); $website = $websiteName ? $this->storeManager->getWebsite($websiteName) : 0; if ($this->helper->isEnabled($website)) { $savedPrograms = $this->registry->registry('programs'); //get saved datafileds from registry if (is_array($savedPrograms)) { $programs = $savedPrograms; } else { //grab the datafields request and save to register $client = $this->helper->getWebsiteApiClient($website); $programs = $client->getPrograms(); $this->registry->unregister('programs'); $this->registry->register('programs', $programs); } //set the api error message for the first option if (isset($programs->message)) { //message $fields[] = ['value' => 0, 'label' => $programs->message]; } elseif (!empty($programs)) { //loop for all programs option foreach ($programs as $program) { if (isset($program->id) && $program->status == 'Active') { //@codingStandardsIgnoreStart $fields[] = ['value' => $program->id, 'label' => addslashes($program->name)]; //@codingStandardsIgnoreEnd } } } } return $fields; }
protected function tearDown() { $this->registry->unregister('composite_configure_result_error_message'); $this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID); $this->registry->unregister('current_product'); $this->registry->unregister('product'); }
public function replaceCodeInRegistry($code) { if ($this->_registry->registry(static::REG_REFERRAL_CODE)) { $this->_registry->unregister(static::REG_REFERRAL_CODE); } $this->_registry->register(static::REG_REFERRAL_CODE, $code); }
public function tearDown() { $this->_coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID); /** @var \Magento\Customer\Model\CustomerRegistry $customerRegistry */ $customerRegistry = $this->_objectManager->get('Magento\\Customer\\Model\\CustomerRegistry'); //Cleanup customer from registry $customerRegistry->remove(1); }
public function testUnregister() { $key = 'csv_adapter'; $valueObj = $this->getMock('\\Magento\\ImportExport\\Model\\Export\\Adapter\\Csv', [], [], '', false, false); $this->registry->register($key, $valueObj); $this->assertEquals($valueObj, $this->registry->registry($key)); $this->registry->unregister($key); $this->assertNull($this->registry->registry($key)); $this->registry->unregister($this->data['key']); $this->assertNull($this->registry->registry($this->data['key'])); }
/** * Minimal price for "regular" user * * @param \Magento\Catalog\Model\Product $product * @param null|\Magento\Store\Model\Store $store Store view * @param bool $inclTax * @return null|float */ public function getCatalogPrice(\Magento\Catalog\Model\Product $product, $store = null, $inclTax = false) { if ($store instanceof \Magento\Store\Model\Store) { $oldStore = $this->storeManager->getStore(); $this->storeManager->setCurrentStore($store); } $this->coreRegistry->unregister('rule_data'); $this->coreRegistry->register('rule_data', new \Magento\Framework\Object(array('store_id' => $product->getStoreId(), 'website_id' => $product->getWebsiteId(), 'customer_group_id' => $product->getCustomerGroupId()))); $minPrice = $product->getPriceModel()->getTotalPrices($product, 'min', $inclTax); if ($store instanceof \Magento\Store\Model\Store) { $this->storeManager->setCurrentStore($oldStore); } return $minPrice; }
/** * Set developerTool Block registry * * @return bool */ public function setDeveloperRegistryBlock($data) { if ($this->_coreRegistry->registry($this->_statusKey)) { $this->_coreRegistry->unregister($this->_statusKey); } $this->_coreRegistry->register($this->_statusKey, $data); return true; }
/** * Set developerTool registry * * @return bool */ public function setDeveloperRegistry($data) { $this->log($data); if ($this->_coreRegistry->registry($this->_dataKey)) { $this->_coreRegistry->unregister($this->_dataKey); } $this->_coreRegistry->register($this->_dataKey, $data); return true; }
/** * Unset registry item * @param array|string $unsetData * @return void */ protected function unsetRegistryData($unsetData) { if (is_array($unsetData)) { foreach ($unsetData as $item) { $this->coreRegistry->unregister($item); } } else { $this->coreRegistry->unregister($unsetData); } }
/** * Address before save event handler * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { if ($this->_coreRegistry->registry(self::VIV_CURRENTLY_SAVED_ADDRESS)) { $this->_coreRegistry->unregister(self::VIV_CURRENTLY_SAVED_ADDRESS); } /** @var $customerAddress Address */ $customerAddress = $observer->getCustomerAddress(); if ($customerAddress->getId()) { $this->_coreRegistry->register(self::VIV_CURRENTLY_SAVED_ADDRESS, $customerAddress->getId()); } else { $configAddressType = $this->_customerAddress->getTaxCalculationAddressType(); $forceProcess = $configAddressType == AbstractAddress::TYPE_SHIPPING ? $customerAddress->getIsDefaultShipping() : $customerAddress->getIsDefaultBilling(); if ($forceProcess) { $customerAddress->setForceProcess(true); } else { $this->_coreRegistry->register(self::VIV_CURRENTLY_SAVED_ADDRESS, 'new_address'); } } }
/** * delete failed order * * @param \Magento\Sales\Model\Order $order * * @throws \Magento\Framework\Exception\LocalizedException */ public function deleteOrder($order) { if ($order->canUnhold()) { $order->unhold(); } $order->cancel(); /* hack isSecureArea flag, otherwise actionValidator fails */ $this->_registry->unregister('isSecureArea'); $this->_registry->register('isSecureArea', true); $order->delete(); }
/** * Dispatch request * * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface * @throws \Magento\Framework\Exception\NotFoundException */ public function execute() { $id = $this->getRequest()->getParam('cadou_id'); $model = $this->_objectManager->create('Alin\\Cadou\\Model\\Cadou'); if ($id) { $model->load($id); if (!$model->getId()) { $this->messageManager->addError(__('This cadou no longer exists.')); /** \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('*/*/'); } else { $model->delete(); $this->_coreRegistry->unregister('cadou', $model); $this->messageManager->addSuccess(__('The selected record has been deleted.')); $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('*/*/'); } } }
/** * No data fixture nor is there a customer Id set in the registry. */ public function testToHtmlNoCustomerId() { $this->coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID); $customerData['account'] = array(Customer::FIRSTNAME => 'John', Customer::LASTNAME => 'Doe', Customer::EMAIL => '*****@*****.**', Customer::GROUP_ID => 1, Customer::WEBSITE_ID => 1); $customerData['address'] = array(); $this->context->getBackendSession()->setCustomerData($customerData); $html = $this->block->toHtml(); $this->assertNotContains('name="cart" title="Shopping Cart"', $html); $this->assertNotContains('name="wishlist" title="Wishlist"', $html); $this->assertStringMatchesFormat('%a name="account[firstname]" %s value="John" %a', $html); $this->assertStringMatchesFormat('%a name="account[lastname]" %s value="Doe" %a', $html); $this->assertStringMatchesFormat('%a name="account[email]" %s value="*****@*****.**" %a', $html); }
/** * Set Google Content Client Instance * * @param \Zend_Http_Client $client * @return $this */ public function setClient($client) { $this->_coreRegistry->unregister($this->_clientRegistryId); $this->_coreRegistry->register($this->_clientRegistryId, $client); return $this; }
/** * Execute per test cleanup. */ public function tearDown() { $this->coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID); }
protected function tearDown() { $this->registry->unregister(IntegrationController::REGISTRY_KEY_CURRENT_INTEGRATION); parent::tearDown(); }
/** * @param $shipperResponse * @return Mage_Shipping_Model_Rate_Result */ protected function parseShipperResponse($shipperResponse) { $debugRequest = $this->shipperRequest; $debugData = ['request' => json_encode($debugRequest, JSON_PRETTY_PRINT), 'response' => $shipperResponse]; if (!is_object($shipperResponse)) { $this->shipperLogger->postInfo('Shipperhq_Shipper', 'Shipper HQ did not return a response', $debugData); return $this->returnGeneralError('Shipper HQ did not return a response - could not contact ShipperHQ. Please review your settings'); } $transactionId = $this->shipperRateHelper->extractTransactionId($shipperResponse); $this->registry->unregister('shipperhq_transaction'); $this->registry->register('shipperhq_transaction', $transactionId); //first check and save globals for display purposes $globals = array(); if (is_object($shipperResponse) && isset($shipperResponse->globalSettings)) { $globals = $this->shipperRateHelper->extractGlobalSettings($shipperResponse); $globals['transaction'] = $transactionId; $this->shipperDataHelper->setGlobalSettings($globals); } $result = $this->rateFactory->create(); // If no rates are found return error message if (!empty($shipperResponse->errors)) { $this->shipperLogger->postInfo('Shipperhq_Shipper', 'Shipper HQ returned an error', $debugData); if (isset($shipperResponse->errors)) { foreach ($shipperResponse->errors as $error) { $this->appendError($result, $error, $this->_code, $this->getConfigData('title')); } } return $result; } elseif (!isset($shipperResponse->carrierGroups)) { // DO NOTHING } if (isset($shipperResponse->carrierGroups)) { $carrierRates = $this->processRatesResponse($shipperResponse, $transactionId, $globals); } else { $carrierRates = []; } $this->persistAddressValidation($shipperResponse); if (count($carrierRates) == 0) { $this->shipperLogger->postInfo('Shipperhq_Shipper', 'Shipper HQ did not return any carrier rates', $debugData); return $result; } foreach ($carrierRates as $carrierRate) { if (isset($carrierRate['error'])) { $carriergroupId = null; $carrierGroupDetail = null; if (array_key_exists('carriergroup_detail', $carrierRate) && !is_null($carrierRate['carriergroup_detail'])) { if (array_key_exists('carrierGroupId', $carrierRate['carriergroup_detail'])) { $carriergroupId = $carrierRate['carriergroup_detail']['carrierGroupId']; } $carrierGroupDetail = $carrierRate['carriergroup_detail']; } $this->appendError($result, $carrierRate['error'], $carrierRate['code'], $carrierRate['title'], $carriergroupId, $carrierGroupDetail); continue; } if (!array_key_exists('rates', $carrierRate)) { $this->shipperLogger->postInfo('Shipperhq_Shipper', 'Shipper HQ did not return any rates for ' . $carrierRate['code'] . ' ' . $carrierRate['title'], $debugData); } else { $baseRate = 1; $baseCurrencyCode = $this->shipperDataHelper->getBaseCurrencyCode(); foreach ($carrierRate['rates'] as $rateDetails) { if (isset($rateDetails['currency'])) { if ($rateDetails['currency'] != $baseCurrencyCode || $baseRate != 1) { $baseRate = $this->shipperDataHelper->getBaseCurrencyRate($rateDetails['currency']); if (!$baseRate) { $error = __('Can\'t convert rate from "%1".', $rateDetails['currency']); $this->appendError($result, $error, $carrierRate['code'], $carrierRate['title'], $rateDetails['carriergroup_detail']['carrierGroupId'], $rateDetails['carriergroup_detail']); $this->shipperLogger->postCritical('Shipperhq_Shipper', 'Currency Rate Missing', 'Currency code in shipping rate is ' . $rateDetails['currency'] . ' but there is no currency conversion rate configured so we cannot display this shipping rate'); continue; } } } $rate = $this->rateMethodFactory->create(); $rate->setCarrier($carrierRate['code']); $lengthCarrierCode = strlen($carrierRate['code']); $rate->setCarrierTitle(__($carrierRate['title'])); $methodCombineCode = preg_replace('/&|;| /', "", $rateDetails['methodcode']); //SHQ16-1520 - enforce limit on length of shipping carrier code and method code of less than 35 - M2 hard limit of 40 $lengthMethodCode = strlen($methodCombineCode); if ($lengthCarrierCode + $lengthMethodCode > 40) { $total = $lengthCarrierCode + $lengthMethodCode; $trim = $total - 35; $methodCombineCode = substr($methodCombineCode, $trim, $lengthMethodCode); } $rate->setMethod($methodCombineCode); $rate->setMethodTitle(__($rateDetails['method_title'])); $rate->setTooltip($rateDetails['tooltip']); if (array_key_exists('method_description', $rateDetails)) { $rate->setMethodDescription(__($rateDetails['method_description'])); } $rate->setCost($rateDetails['cost'] * $baseRate); $rate->setPrice($rateDetails['price'] * $baseRate); if (array_key_exists('carrier_type', $rateDetails)) { $rate->setCarrierType($rateDetails['carrier_type']); } if (array_key_exists('carrier_id', $rateDetails)) { $rate->setCarrierId($rateDetails['carrier_id']); } if (array_key_exists('dispatch_date', $rateDetails)) { $rate->setDispatchDate($rateDetails['dispatch_date']); } if (array_key_exists('delivery_date', $rateDetails)) { $rate->setDeliveryDate($rateDetails['delivery_date']); } if (array_key_exists('carriergroup_detail', $rateDetails) && !is_null($rateDetails['carriergroup_detail'])) { $carrierGroupDetail = $baseRate != 1 ? $this->updateWithCurrrencyConversion($rateDetails['carriergroup_detail'], $baseRate) : $rateDetails['carriergroup_detail']; $rate->setCarriergroupShippingDetails($this->shipperDataHelper->encode($carrierGroupDetail)); if (array_key_exists('carrierGroupId', $carrierGroupDetail)) { $rate->setCarriergroupId($carrierGroupDetail['carrierGroupId']); } if (array_key_exists('checkoutDescription', $carrierGroupDetail)) { $rate->setCarriergroup($carrierGroupDetail['checkoutDescription']); } } $result->append($rate); } if (isset($carrierRate['shipments'])) { $this->persistShipments($carrierRate['shipments']); } } } return $result; }
protected function tearDown() { $this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID); }
/** * Verify that the header text is correct for a new customer. */ public function testGetHeaderTextNewCustomer() { $this->coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID); $this->assertEquals('New Customer', $this->block->getHeaderText()); }
/** * Execute per test cleanup. */ public function tearDown() { $this->registry->unregister(RegistryConstants::CURRENT_GROUP_ID); }
/** * Execute post test cleanup. */ public function tearDown() { $this->coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID); $this->block->setCollection(null); }
/** * Save/reset the order as transactional data. * * @param \Magento\Framework\Event\Observer $observer * * @return $this * * @throws \Magento\Framework\Exception\LocalizedException */ public function execute(\Magento\Framework\Event\Observer $observer) { try { $order = $observer->getEvent()->getOrder(); $status = $order->getStatus(); $storeId = $order->getStoreId(); $store = $this->storeManager->getStore($storeId); $storeName = $store->getName(); $websiteId = $store->getWebsiteId(); $customerEmail = $order->getCustomerEmail(); // start app emulation $appEmulation = $this->emulationFactory->create(); $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId); $emailOrder = $this->emailOrderFactory->create()->loadByOrderId($order->getEntityId(), $order->getQuoteId()); //reimport email order $emailOrder->setUpdatedAt($order->getUpdatedAt())->setCreatedAt($order->getUpdatedAt())->setStoreId($storeId)->setOrderStatus($status); if ($emailOrder->getEmailImported() != \Dotdigitalgroup\Email\Model\Contact::EMAIL_CONTACT_IMPORTED) { $emailOrder->setEmailImported(null); } //if api is not enabled if (!$store->getWebsite()->getConfig(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_API_ENABLED)) { return $this; } // check for order status change $statusBefore = $this->registry->registry('sales_order_status_before'); if ($status != $statusBefore) { //If order status has changed and order is already imported then set modified to 1 if ($emailOrder->getEmailImported() == \Dotdigitalgroup\Email\Model\Contact::EMAIL_CONTACT_IMPORTED) { $emailOrder->setModified(\Dotdigitalgroup\Email\Model\Contact::EMAIL_CONTACT_IMPORTED); } } // set back the current store $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); $emailOrder->save(); //@codingStandardsIgnoreStart //Status check automation enrolment $configStatusAutomationMap = unserialize($this->scopeConfig->getValue(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER_STATUS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $order->getStore())); //@codingStandardsIgnoreEnd if (!empty($configStatusAutomationMap)) { foreach ($configStatusAutomationMap as $configMap) { if ($configMap['status'] == $status) { //send to automation queue $this->doAutomationEnrolment(['programId' => $configMap['automation'], 'automationType' => 'order_automation_' . $status, 'email' => $customerEmail, 'order_id' => $order->getId(), 'website_id' => $websiteId, 'store_name' => $storeName]); } } } //If customer's first order if ($order->getCustomerId()) { $orders = $this->orderCollectionFactory->create()->addFieldToFilter('customer_id', $order->getCustomerId()); if ($orders->getSize() == 1) { $automationTypeNewOrder = \Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_TYPE_CUSTOMER_FIRST_ORDER; $programIdNewOrder = $this->helper->getAutomationIdByType('XML_PATH_CONNECTOR_AUTOMATION_STUDIO_FIRST_ORDER', $order->getWebsiteId()); //send to automation queue $this->doAutomationEnrolment(['programId' => $programIdNewOrder, 'automationType' => $automationTypeNewOrder, 'email' => $customerEmail, 'order_id' => $order->getId(), 'website_id' => $websiteId, 'store_name' => $storeName]); } } //admin oder when editing the first one is canceled $this->registry->unregister('sales_order_status_before'); } catch (\Exception $e) { throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage())); } return $this; }
public function tearDown() { $this->_backendSession->unsCustomerData(); $this->_coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID); }