Magento2: is there a product list limit? - magento2

In an existing Magento2 shop I have a category that contains a lot of products (over 2000). But when I click on it, only the first 190 of them are shown. Is there any way to set that limit, and if so, where?
Or is there an other reason why my products list is limited to 190 products? Any ideas?

You can get the 190 product form below script
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
/** #var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
/** Apply filters here */
$productCollection->addAttributeToSelect('*')
$productCollection->setPageSize(190)
$productCollection->load();

Used setPageSize() and setCurPag‌​e()
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$data = $objectManager->create('Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection')->setPageSize(10)->setCurPag‌​e(1);

Related

Magento 2 - Split an order in two parts

I am trying to make a functionality to split an order in 2 which has 2 different Seller Item in my custom module.
Do you have any idea about how to do this pro-grammatically please ?
Reference link split orders in magento
Reference link Magento - 2
Is possible split the order by seller attribute. You just need to intercept the placeOrder function using around action plugin.
There, you can map all of the items into cart and create a new order for each product you want.
Please refer (In this case, split by product SKU getSku, you can change for any attribute):
public function aroundPlaceOrder(
\Magento\Quote\Model\QuoteManagement $subject,
callable $proceed,
$cartId,
$paymentMethod = null
) {
$quote = $this->quoteRepository->getActive($cartId);
$quotes = [];
foreach ($quote->getAllVisibleItems() as $item) {
$quotes[$item->getProduct()->getSku()][] = $item;
}
foreach ($quotes as $groups => $items) {
...
Also, you can take a look here:
https://github.com/magestat/magento2-split-order/blob/develop/Plugin/SplitQuote.php
Thanks!

Validation Drupal Form doesn't works

I created these two functions to be able to modify the validation of my Drupal form by following different subjects on SOF or other information. But my query never goes into the validate function, and I do not understand why ...
/**
* Implements hook_form_FORM_ID_alter().
*/
function *****_form_simplenews_block_form_1_alter(&$form, &$form_state) {
// Modify some form settings
$form['mail']['#title_display'] = 'invisible';
$form['mail']['#size'] = 40;
$form['mail']['#attributes']['placeholder'] = t('Enter your email address');
$form['submit']['#value'] = t('OK');
$form['#validate'][0] = '*****_simplenews_block_form_validate';
}
/**
* Validate the mail address for simplenews
*
* #param $form
* #param $form_state
*/
function *****_simplenews_block_form_validate($form, &$form_state) {
kpr($form);die();
if (!valid_email_address($form_state['values']['mail']) && $form_state['values']['check_robot']) {
form_set_error('mail', t("Error, please try again"));
form_set_error('submit', "You are a robot.");
}
}
I went to see on the doc of the Drupal API (https://www.drupal.org/files/fapi_workflow_7.x_v1.1.png) , and it seems that I do what it is necessary, so if someone could help me, I would be rather happy, thank you in advance!
Well, my bad !
The action form submit the form to a webservice. So it will never been validated by the Drupal form workflow.

Get articles from TYPO3 news extension

I want to realize an image slide, that show the last 3 news from the news extension on it.
So - I'm obvioulsy new to TYPO3 - I somehow need to fetch the data from the news extension.
I would prefer doing it inside the new extension, so I guess - from what I know so far - it should look somehow like this
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$orderRepository = $objectManager->get('Tx_News_Extension_Path_To_Articles'); // don't know path
$articles = $orderRepository->find(3, BY-DATE, DESC); // don't know the command
$this->view->assign('articles', $articles);
I head of another way by doing it through TypoScript. Maybe I could use this:
lib.news_list < lib.news
lib.news_list {
action = list
switchableControllerActions.News.1 = list
}
Would be glad to get some advise.
Chris
One option is to add a function like this to your repository:
public function findLastByDate($amount){
$query = $this->createQuery();
$query->setLimit($amount);
$query->setOrderings(array(
'date' => \TYPO3\CMS\Extbase\Persistence\Generic\QueryInterface::ORDER_DESCENDING
));
return $query->execute();
}
And call it in your controller:
$articles = $this->orderRepository->findLastByDate(3);

Use tt_address fields in direct_mail newsletter

I am using TYPO3 6.2.11, tt_address 2.3.5 and direct_mail 4.0.1 and sent me some test newsletters from a internal TYPO3-Page. Everything works fine.
Now, I want to send some data fields from my tt_address-table like name or title for example.
What's the name of the tt_address-MARKER, I'll use at my page content?
I also add the follwing to [basic.addRecipFields] at the direct_mail-Extension:
name,first_name,last_name,email,description,title
But nothing happens. I can't use tt_address-fields at my direct_mail newsletter. I hope someone can help me, thanks.
The other opportunity is to use fe_user-data for my newsletter (felogin). How can I use felogin-fields like passwordor username at my template?
You need to prefix the fields with USER_ and wrap the marker in ###. So e.g. if you'd like to use the e-mail address, you write ###USER_email###. You can find all possibilities in the Direct Mail documentation.
A note on sending the password: This would be a huge security risk but it's not possible anyway because passwords of fe_users are stored at least hashed (and nowadays also encrypted) in the database. But you can use the ###SYS_AUTHCODE### marker to generate an authentication code you can use in an "edit profile" extension to let the user update his subscription.
If you need fields from other sources or data you're calculating dynamically, you can also create an own extension and implement the Direct Mail mailMarkersHook.
ext_localconf.php:
// Direct Mail personalization hook
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/direct_mail']['res/scripts/class.dmailer.php']['mailMarkersHook']['userunilunewsletterrendering'] =
'My\Extension\Hook\DirectMail->mailMarkersHook';
EXT:extension/Classes/Hook/DirectMail.php:
<?php
namespace My\Extension\Hook;
class DirectMail {
public function mailMarkersHook($params, \DirectMailTeam\DirectMail\Dmailer $dmailer) {
$params['markers']['###USER_SALUTATION###'] = $this->getPersonalizedSalutation($params['row']);
return $params;
}
/**
* #param $row
* #return string
*/
protected function getPersonalizedSalutation($row) {
$personalizedSalutation = 'Dear Sir or Madam';
if (!empty($row['last_name']) && !empty($row['gender'])) {
if ($row['gender'] === 'm') {
$personalizedSalutation = 'Dear Mr. ' . $row['last_name'];
} elseif ($row['gender'] === 'f') {
$personalizedSalutation = 'Dear Ms. ' . $row['last_name'];
}
}
return $personalizedSalutation;
}
}

Behat + mink how to test jquery-ui autocomplete field?

I'm using Behat to test a registration page.
This page contains a few fields with autocompletion.
User fills in some value in the field, page waits 500 milliseconds, makes an ajax-request and displays some options along with a relevant message (no items found / several items found / one item found).
I'm using a predefined step "I fill in field with value" (tried to use "I fill in value for field" instead).
Next step is custom, similar to one described in documentation - I'm just waiting for message to appear and check that it has correct text.
But after filling the field Mink removes focus from it, causing blur event to be fired on the field.
Jquery-ui clears the field value in response to this blur event, so after 500 milliseconds field is empty and ajax request is aborted.
How can I fix this problem?
Behat v2.5.0
Mink v1.5.0
Mink-extension v1.3.3
Jquery-ui v1.8.21
Selenium v2.44.0
Solution below is specific to my markup code but should be easily adapted to yours. You might need to modify it.
Assuming that selecting auto suggested option in textbox. Autosuggestion options appear as <li> elements after user’s key strokes. <li> element presents in the page however its content is empty at the beginning so there is nothing to be selected by behat. To solve the problem, non existing content between <li> tags is wrapped with <label> tag.
User types in this auto suggestion field:
<input name="brand" type="text" />
Where autosuggestion data appears:
<ul>
<li><label>{{ suggestion }}</label></li>
</ul>
Gherkin:
When I fill in "brand" with "S"
And I wait 1 seconds
Then I select autosuggestion option "Sula"
And I wait 1 seconds
......
FeatureContext:
/**
* #Given /^I wait (\d+) seconds$/
*/
public function iWaitSeconds($seconds)
{
sleep($seconds);
}
/**
* #Then /^I select autosuggestion option "([^"]*)"$/
*
* #param $text Option to be selected from autosuggestion
* #throws \InvalidArgumentException
*/
public function selectAutosuggestionOption($text)
{
$session = $this->getSession();
$element = $session->getPage()->find(
'xpath',
$session->getSelectorsHandler()->selectorToXpath('xpath', '*//*[text()="'. $text .'"]')
);
if (null === $element) {
throw new \InvalidArgumentException(sprintf('Cannot find text: "%s"', $text));
}
$element->click();
}
#Scenario: I'm stuck
Given I use jquery-ui-autocomplete
And I can not test it with behat
Then I trigger keyDown event like this:
"""
/**
* #When I select :entry after filling :value in :field
*/
public function iFillInSelectInputWithAndSelect($entry, $value, $field)
{
$page = $this->getSession()->getPage();
$field = $this->fixStepArgument($field);
$value = $this->fixStepArgument($value);
$page->fillField($field, $value);
$element = $page->findField($field);
$this->getSession()->getDriver()->keyDown($element->getXpath(), '', null);
$this->getSession()->wait(500);
$chosenResults = $page->findAll('css', '.ui-autocomplete a');
foreach ($chosenResults as $result) {
if ($result->getText() == $entry) {
$result->click();
return;
}
}
throw new \Exception(sprintf('Value "%s" not found', $entry));
}
"""
Use this to Fill in the search box: (using the ID selector)
/**
* #Then I type :text into search box
*/
public function iTypeTextIntoSearchBox($text)
{
$element = $this->getSession()->getPage()->findById('searchInput');
$script = "$('#searchInput').keypress();";
$element->setValue($text);
$this->getSession()->evaluateScript($script);
}