ScottyScotch
Писатель
- Регистрация
- 16 Май 2016
- Сообщения
- 9
- Реакции
- 0
In Magento 2, would it be wrong to create a Factory model that allows me to get a factory for any of the models in my module? The reason I ask is that injecting model factories into my blocks / controllers where I need them and it is becoming quite difficult to manage. The proposed Factory of factories model I propose would still use DI to inject the factory classes so nothing would be hardcoded.
Here's some example code:
I'm trying the creation cart via Soap with Java code below. The quote is created and inserted into the table, but when I add the product nothing happens and does not return any error. Already I researched on the internet and have not found much information about Magento with Java. Does anyone have any idea what might be missing in this code?
package clientesoapmagento;
import java.net.MalformedURLException; import java.util.List;
public class ClienteSoapMagento {
I have successfully override Customer Account Management model in Magento 2.
I have to update some code in authenticate function but i can not success its redirect to login page.
also I did lots of R&D but not able to get any proper solution.
also i have to check System configuration value in model file.
Can any one please help me if anyone knows?
Here's some example code:
Код:
namespace Vendor/Module/Model;
class Factory
{
protected $_factories = null;
public function __construct(
FirstModelFactory $firstModelFactory,
SecondModelFactory $secondModelFactory
) {
$this->_factories = array(
'FirstModelFactory' => $firstModelFactory,
'SecondModelFactory' => $secondModelFactory
);
}
public function getFactory($class)
{
return isset($this->_factories[$class])
? $this->_factories[$class]
: false;
}
}
I'm trying the creation cart via Soap with Java code below. The quote is created and inserted into the table, but when I add the product nothing happens and does not return any error. Already I researched on the internet and have not found much information about Magento with Java. Does anyone have any idea what might be missing in this code?
package clientesoapmagento;
import java.net.MalformedURLException; import java.util.List;
public class ClienteSoapMagento {
Код:
public static final String URL = "http://example.com.ru/index.php/api/v2_soap";
public static final String USER = "XXXXXX";
public static final String API_KEY = "XXXXXXXXXXXX";
[/ Code]
public static void main (String [] args) throws MalformedURLException {
[code]
MagentoService service = new MagentoService();
PortType port = service.getPort();
System.out.println(service.getServiceName());
System.err.println(port); // OK
LoginParam loginParam = new LoginParam();
loginParam.setUsername(USER);
loginParam.setApiKey(API_KEY);
LoginResponseParam session = port.login(loginParam);
String sessionId = session.getResult();
System.out.println("sessionId : " + sessionId); // OK
StoreListRequestParam param = new StoreListRequestParam();
param.setSessionId(sessionId);
StoreListResponseParam storeListRespParam = port.storeList(param);
StoreEntityArray storeEntityArray = storeListRespParam.getResult();
List<StoreEntity> stores = storeEntityArray.getComplexObjectArray();
System.out.println(">>>> stores " + stores.size()); // OK
ShoppingCartCreateRequestParam shoppingCartCreateRequestParam = new ShoppingCartCreateRequestParam();
shoppingCartCreateRequestParam.setSessionId(sessionId);
shoppingCartCreateRequestParam.setStore("1");
ShoppingCartCreateResponseParam resp = port.shoppingCartCreate(shoppingCartCreateRequestParam);
int quoteId = resp.getResult();
System.out.println(">>>> quoteId " + quoteId); //OK
ShoppingCartProductAddRequestParam prodcutAddParam = new ShoppingCartProductAddRequestParam();
ShoppingCartProductEntityArray array = new ShoppingCartProductEntityArray();
ShoppingCartProductEntity produto = new ShoppingCartProductEntity();
produto.setProductId("1");
produto.setSku("D15");
produto.setQty(1.00);
produto.setLinks(null);
produto.setBundleOption(null);
produto.setBundleOptionQty(null);
produto.setOptions(null);
array.getComplexObjectArray().add(produto);
prodcutAddParam.setProductsData(array);
prodcutAddParam.setQuoteId(quoteId);
prodcutAddParam.setSessionId(sessionId);
prodcutAddParam.setStore("1");
ShoppingCartProductAddResponseParam prodAddResult = new ShoppingCartProductAddResponseParam();
System.out.println("product added? " + prodAddResult.isResult()); // RETURN FALSE
EndSessionParam endSessionParam = new EndSessionParam();
endSessionParam.setSessionId(sessionId);
port.endSession(endSessionParam);
}
I have successfully override Customer Account Management model in Magento 2.
I have to update some code in authenticate function but i can not success its redirect to login page.
also I did lots of R&D but not able to get any proper solution.
Код:
namespace xxxxx\xxxxx\Model\Rewrite\Customer;
use Magento\Customer\Api\AccountManagementInterface;
class AccountManagement extends \Magento\Customer\Model\AccountManagement
{
public function authenticate($username, $password)
{
$this->checkPasswordStrength($password);
try {
$customer = $this->customerRepository->get($username);
} catch (NoSuchEntityException $e) {
throw new InvalidEmailOrPasswordException(__('Invalid login or password.'));
}
//My condition
if()
{
echo "My Custom logic";
die;
}else
{
//else
$hash = $this->customerRegistry->retrieveSecureData($customer->getId())->getPasswordHash();
if (!$this->encryptor->validateHash($password, $hash)) {
throw new InvalidEmailOrPasswordException(__('Invalid login or password.'));
}
if ($customer->getConfirmation() && $this->isConfirmationRequired($customer)) {
throw new EmailNotConfirmedException(__('This account is not confirmed.'));
}
$customerModel = $this->customerFactory->create()->updateData($customer);
$this->eventManager->dispatch(
'customer_customer_authenticated',
['model' => $customerModel, 'password' => $password]
);
$this->eventManager->dispatch('customer_data_object_login', ['customer' => $customer]);
}
}
}
also i have to check System configuration value in model file.
Can any one please help me if anyone knows?
Последнее редактирование модератором: